Software Quality Assurance & Testing Asked on December 27, 2020
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.access$000(ChromeDriverService.java:35)
and same code is working with .exe
files but not when we are loading through WebDriverManager.
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();
Answered by Upkar Singh on December 27, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP