We can run our tests in different browsers in selenium Webdriver, previously we need to executable files to run our test in any browser. But now we can achieve without using exe files & with the help of WebDriverManager following below syntax to open chrome browser.
WebDriverManager.iedriver().setup();
driver = new ChromeDriver();
Driver class I have defined below code:
public static WebDriver getDriver(){
try{
if(driver == null) {
/* PropertiesFileReader obj=new PropertiesFileReader();
Properties properties=obj.getproperty();
openBrowser(properties.getProperty("browserName"), properties.getProperty("URL")); */
WebDriverManager.iedriver().setup();
driver = new ChromeDriver();
}
}catch(Exception e) {
e.printStackTrace();
}
return driver;
}
I have login page and logintestcase, I am calling getDriver()
method from logintest class using below code:
public LoginPage loginpage=PageFactory.initElements(Driver.getDriver(), LoginPage.class);
But I am getting exception :
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:843)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:135)
at org.openqa.selenium.chrome.ChromeDriverService.access000ドル(ChromeDriverService.java:35)
and same code is working with .exe
files but not when we are loading through WebDriverManager.
1 Answer 1
Try this may this code help you-
WebDriver driver;
public static WebDriver getDriver(){
try{
if(driver == null) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
}
}catch(Exception e) {
e.printStackTrace();
}
return driver;
}
If you want to add more capabilities in webdrivermanager try this too-
WebDriverManager.chromedriver()
.version("2.40")
.arch32()
.proxy("myproxyhostname:80")
.proxyUser("myusername")
.proxyPass("myawesomePassword")
.setup();
-
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See slf4j.org/codes.html#StaticLoggerBinder for further details. io.github.bonigarcia.wdm.WebDriverManagerException: io.github.bonigarcia.wdm.WebDriverManagerException: chromedriver 66.0.3359.181 for WIN64 not found in npm.taobao.org/mirrors/chromedriverjay– jay2019年05月03日 07:14:58 +00:00Commented May 3, 2019 at 7:14
-
You need to add following jar file in your classpath:
slf4j-simple-1.6.2.jar
and for chromedriver exception try to download the correct version by using.Version()
capabilitiy ofWebDriverManager
.Upkar Singh– Upkar Singh2019年05月03日 07:31:03 +00:00Commented May 3, 2019 at 7:31 -
nable to read VR Path Registry getting for firefoxdriver, refer ccode-- WebDriverManager.firefoxdriver().version("0.21.0").setup(); driver=new FirefoxDriver();jay– jay2019年05月03日 09:30:15 +00:00Commented May 3, 2019 at 9:30
-
Is your chromeDriver working?Upkar Singh– Upkar Singh2019年05月03日 09:35:14 +00:00Commented May 3, 2019 at 9:35
-
Explore related questions
See similar questions with these tags.
iedriver().setup();
which is used for IE Browser but below you declare the instance ofChromeDriver
.