how to Pass command line argument ( baseURL) for selenium WebDriver -
kindly help. have created runnable jar selenium webdriver suite. have test in multiple environment( qa , demo box, dev ). manager doesnt hard coded below driver.get(baseurl)
as baseurl change according need. script given build team. in command prompt java -jar myproject-1.0.1.jar
so manager has asked me send baseurl command line argument build team not have go script , manually change baseurl. should able change url every time run script command line itself. this
java -jar myproject-1.0.1.jar "http://10.68.14.248:8080/bda/homepage.html"
can please guide me through this. possible send command line arguments selenium web driver driver.get(baseurl)
thanks in advance
from question above recon want pass url @ runtime, means url changes time time beside hardcoded url , want pass @ time automation code runs. so, let me give 2 simple solutions.
- you can send url dynamically or @ run time using javascript executor:
try{ javascriptexecutor js = (javascriptexecutor)driver; js.executescript("var pr=prompt('enter url please:',''); alert(pr);"); thread.sleep(15000l); string url = driver.switchto().alert().gettext(); driver.switchto().alert().accept(); driver.get(url); }catch(throwable e) { system.out.println("failed"); }
use code in place of driver.get();
, prompt box appear when run code , within 15 secs or throw error(you can change time in thread.sleep
) give current valid url , hit enter, navigation go url. can use different url same set of testscripts.
- by using scanner class:
string url = ""; system.out.println("enter url :"); scanner s = new scanner(system.in); url = s.next(); s.close();
by using can give needed url in console (if using eclipse).
i recommend try javascript excutor in code , create runnable jar file , run jar file, know , better solution commandline url passing . let me know :)
Comments
Post a Comment