As we all know, while using Selenium WebDriver for each browser such as Chrome, Firefox, MS Edge or IE, we
need to first separately download its binary file which allows, WebDriver to
handle browsers then we need to provide the absolute path of this binary in the system
properties to launch the respective browsers.
It is actually quite frustrating as
we need to manually check for a different version, install and use this binary
files in our automation scripts.
WebDriver Manager is a solution to all
these problems. WebDriver Manager allows us to:
รผ It checks the version of the browser installed in
your machine (e.g. Chrome, Firefox).
รผ It checks the version of the driver (e.g. chrome driver, geckodriver).
If unknown, it uses the latest version of the driver.
รผ It downloads the WebDriver binary if it is not
present on the WebDriverManager cache (~/.m2/repository/webdriver by
default).
รผ It exports the proper WebDriver Java environment
variables required by Selenium (not done when using WebDriverManager from the
CLI or as a Server)
To Know more about WebDriver Manager. Please click on this link.
To Know more about WebDriver Manager. Please click on this link.
To use WebDriver Manager we need to
download its maven dependency by using this link.
In this blog for demo purposes, I am using below maven dependency.
Now in our automation script instead of writing the below line of code
System.setProperty("webdriver.chrome.driver",
"/absolute/path/to/binary/chromedriver");
System.setProperty("webdriver.gecko.driver",
"/absolute/path/to/binary/geckodriver");
We can use below code to launch chrome browser
WebDriverManager.chromedriver().setup();
Below code to launch FireFox browser
WebDriverManager.firefoxdriver().setup();
Full Code would be something like:
I got this error:
ReplyException in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at io.github.bonigarcia.wdm.WebDriverManager.(WebDriverManager.java:93)
at test.TestDriverManager.main(TestDriverManager.java:10)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
I using the same WebDriverManager version and the run the same Full Code
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
ReplySLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I got this issue:
Apr 16, 2019 10:04:54 AM java.util.prefs.WindowsPreferences
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
we are getting error:
ReplyException in thread "main" java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.toString(Ljava/io/InputStream;Ljava/nio/charset/Charset;)Ljava/lang/String;
Do we need to add any dependency in pom.xml apart from webdrivermanager dependency ?
Hi Ankura,
ReplyWe are getting error:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.toString(Ljava/io/InputStream;Ljava/nio/charset/Charset;)Ljava/lang/String;
Do we need to add any dependency in pom.xml apart from webdrivermanager dependency ?
Hi Ankur jain,
ReplyWhat is your approach to resolve if the multiple builds fail and jenkins slave is not responding like take longer time for execution than required?
it is seriously not working. I am really impressed by your other blogs but not this one.
ReplyHi Abhishek ,Can you please share exact error message screenshot,code and issue you are facing while implementing this on my email id ankur.jain.cs@gmail.com.
ReplyTill now lot of people have implemented this without any issue and the issue that might have reported out is due to other incorrect dependencies in their pom.xml.
Happy to help you out in case of any issue..
Hi Ankur,
ReplyCan you please help with below issue.
I have added dependencies in pom.xml
io.github.bonigarcia
webdrivermanager
4.2.2
And below is the code to initiate browser
import org.openqa.selenium.WebDriver;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebDriverManagerPractice {
//static WebDriver driver;
public static void main(String[] args) {
//WebDriverManager.chromedriver().setup();
//WebDriver driver = new ChromeDriver();
WebDriverManager.edgedriver().setup();
WebDriver driver = new EdgeDriver();
driver.get("www.google.com");
Error:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.toString(Ljava/io/InputStream;Ljava/nio/charset/Charset;)Ljava/lang/String;
at io.github.bonigarcia.wdm.versions.Shell.runAndWaitNoLog(Shell.java:66)
at io.github.bonigarcia.wdm.versions.Shell.runAndWaitArray(Shell.java:55)
at io.github.bonigarcia.wdm.versions.Shell.runAndWait(Shell.java:49)
at io.github.bonigarcia.wdm.versions.VersionDetector.getBrowserVersionInWindows(VersionDetector.java:220)
at io.github.bonigarcia.wdm.versions.VersionDetector.getDefaultBrowserVersion(VersionDetector.java:180)
at io.github.bonigarcia.wdm.managers.EdgeDriverManager.getBrowserVersionFromTheShell(EdgeDriverManager.java:137)
at io.github.bonigarcia.wdm.WebDriverManager.detectBrowserVersion(WebDriverManager.java:718)
at io.github.bonigarcia.wdm.WebDriverManager.resolveDriverVersion(WebDriverManager.java:587)
at io.github.bonigarcia.wdm.WebDriverManager.manage(WebDriverManager.java:539)
at io.github.bonigarcia.wdm.WebDriverManager.setup(WebDriverManager.java:287)
at sellinumPractice.WebDriverManagerPractice.main(WebDriverManagerPractice.java:14)