java - why chrome driver is not working in @Before? -
i have simple code
public class pageavailable { @test public void test() { system.setproperty("webdriver.chrome.driver", "c:/users/jars/chromedriver_win32/chromedriver.exe"); webdriver driver = new chromedriver(); driver.get("https://....net"); system.out.println(driver.gettitle()); driver.close(); }}
above code working fine
want code in more structure way
public class pageavailable { webdriver driver = new chromedriver(); @before public void be(){ system.setproperty("webdriver.chrome.driver", "c:/users/jars/chromedriver_win32/chromedriver.exe"); driver.get("....net"); } @test public void test() { driver.get("https://...net"); system.out.println(driver.gettitle()); } @after public void af(){ driver.close(); }}
i getting following error after executing above code
java.lang.illegalstateexception: path driver executable must set webdriver.chrome.driver system property; more information, see https://github.com/seleniumhq/selenium/wiki/chromedriver. latest version can downloaded http://chromedriver.storage.googleapis.com/index.html @ com.google.common.base.preconditions.checkstate(preconditions.java:199) @ org.openqa.selenium.remote.service.driverservice.findexecutable(driverservice.java:109) @ org.openqa.selenium.chrome.chromedriverservice.access$000(chromedriverservice.java:32) @ org.openqa.selenium.chrome.chromedriverservice$builder.finddefaultexecutable(chromedriverservice.java:137) @ org.openqa.selenium.remote.service.driverservice$builder.build(driverservice.java:296) @ org.openqa.selenium.chrome.chromedriverservice.createdefaultservice(chromedriverservice.java:88) @ org.openqa.selenium.chrome.chromedriver.(chromedriver.java:116) @ sample.pageavailable.(pageavailable.java:12) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source) @ java.lang.reflect.constructor.newinstance(unknown source) @ org.junit.runners.blockjunit4classrunner.createtest(blockjunit4classrunner.java:217) @ org.junit.runners.blockjunit4classrunner$1.runreflectivecall(blockjunit4classrunner.java:266) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.blockjunit4classrunner.methodblock(blockjunit4classrunner.java:263) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:78) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:57) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:86) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:459) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:678) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:382) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:192)
i think missing side.
in advance help.
webdriver object initialization should happen after 'webdriver.chrome.driver' property set.
public class pageavailable { webdriver driver; @before public void be(){ //set chromedriver path system.setproperty("webdriver.chrome.driver","c:/users/jars/chromedriver_win32/chromedriver.exe"); // initialize chromedriver instance chromdriver exe set in above line. driver = new chromedriver(); driver.get("....net"); } @test public void test() { //load url driver.get("https://...net"); system.out.println(driver.gettitle()); } @after public void af(){ driver.close(); }}
other option can use is, in environment variable set chromedriver.exe path, in case no need set system property.
Comments
Post a Comment