Exception when running ChromeDriver with WebDriverManager in maven project
Asked Answered
D

4

5

I am getting an exception when trying to open the ChromeDriver using WebDriverManager in a Maven project.

The framework I am planning is tended to pull the ChromeDriver from WebDriverManager after adding the dependency in the pom.xml and is intended to use Gauge to perform the tests.

The error occurs at the moment it tries to create a new instance for the ChromeDriver when running the tests.

Here is the exception:

 Error Message: java.lang.NoSuchMethodError: com.google.common.util.concurrent.SimpleTimeLimiter.create(Ljava/util/concurrent/ExecutorService;)Lcom/google/common/util/concurrent/SimpleTimeLimiter;
  Stacktrace: 
  org.openqa.selenium.net.UrlChecker.<init>(UrlChecker.java:64)
  org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:187)
  org.openqa.selenium.remote.service.DriverService.start(DriverService.java:178)
  org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
  org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
  org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:255)
  org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:237)
  org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:138)
  org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:178)
  org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:167)
  org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:124)
  StepTests.setupTest(StepTests.java:26)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  java.lang.reflect.Method.invoke(Unknown Source)
  com.thoughtworks.gauge.execution.MethodExecutor.execute(MethodExecutor.java:38)
  com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.executeHook(HooksExecutor.java:102)
  com.thoughtworks.gauge.execution.HooksExecutor$TaggedHookExecutor.execute(HooksExecutor.java:88)
  com.thoughtworks.gauge.execution.HooksExecutor.execute(HooksExecutor.java:45)
  com.thoughtworks.gauge.processor.MethodExecutionMessageProcessor.executeHooks(MethodExecutionMessageProcessor.java:65)
  com.thoughtworks.gauge.processor.SpecExecutionStartingProcessor.process(SpecExecutionStartingProcessor.java:32)
  com.thoughtworks.gauge.connection.MessageDispatcher.dispatchMessages(MessageDispatcher.java:89)
  com.thoughtworks.gauge.GaugeRuntime.dispatchMessages(GaugeRuntime.java:104)
  com.thoughtworks.gauge.GaugeRuntime.access$100(GaugeRuntime.java:36)
  com.thoughtworks.gauge.GaugeRuntime$2.run(GaugeRuntime.java:85)
  java.lang.Thread.run(Unknown Source)

When running this code:

import com.thoughtworks.gauge.*;
import io.github.bonigarcia.wdm.ChromeDriverManager;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.thoughtworks.gauge.Step;
import static org.junit.Assert.assertEquals;


public class StepTests {
//Holds the WebDriver instance
private WebDriver webDriver;

@BeforeSuite
public static void initializeDriver(){
    ChromeDriverManager.getInstance().setup();
}

@BeforeSpec
public void setupTest(){
    webDriver = new ChromeDriver();
}

--test code--



    @AfterSuite
    public void closeDriver(){
        if (webDriver != null) {
            webDriver.quit();
        }
    }
}

Please inform me if there is something more you need to know to find a solution.

Distinctive answered 14/9, 2017 at 15:1 Comment(0)
A
4

You have a version conflict in Guava. Selenium WebDriver (not WebDriverManager) depends transitively of a given version of Guava, and it seems you are using another one in your project. I would use the latest versions of both.

Alithea answered 15/9, 2017 at 13:21 Comment(2)
The current version of Guava is guava-21.0.jar if this helps.Distinctive
Is there a workaround I would do meanwhile? Thanks in advance.Distinctive
B
2

Yes, working for me after adding the guava dependency :

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.0.1-jre</version>
</dependency>
Basidium answered 19/2, 2019 at 10:40 Comment(0)
K
0

1st Possible Solution

2nd Possible Solution

Refer this answer only if the problem is not fixed with the 1st Solution.

I have faced this issue and found no accepted answers on SO. I have figured this out by reading it on a non-SO link and pasting it here for future references.

We need to figure out the exact problem first.

If you are using IntelliJ or Eclipse, you need to go to the Run/Debug Configurations, and add a VM argument,

-ea -verbose:class

Now, re-run your test. This will start printing out the classes and the jars from which those classes are being imported and used. In your specific case, if you search for SimpleTimeLimiter, you will see the package from which it is imported.

Since, there has been a conflict of package versions, this error has come up. One jar dependency would be referring to an earlier guava version and this jar would be present early in the classpath. This will avoid the intended class-path to be used. To be more precise, there would be some package which is importing guava earlier than the one which you have written in your pom.xml.

How is that possible?

Let us assume, yours is a project which imports a package dog-2.0.jar and animal-2.0.jar. Now, you might be unaware that dog-2.0.jar internally imports animal-1.0.jar. So, owing to this dependency of imports, JVM will import a class named Animal.class which would be coming from animal-1.0.jar instead of the Animal.class you / your project is expecting from animal-2.0.jar.

And then?

JVM will get the reference of Animal.class even before it reaches your intended import of animal-2.0.jar. Hence, the order in which the jar files are being imported (class-path) will un-intentionally mess with this transitive dependency.

What can I do?

You can right-click on your project in INtelliJ and something similar for Eclipse. Click on

Open Module Settings -> Click on Dependencies

You will get the list of jars being imported here. You can re-arrange the order of the jars. You can push dog-2.0.jar right below your animal-2.0.jar dependency. This will fix the problem.

Kyser answered 16/9, 2020 at 12:5 Comment(0)
D
0

I resolved this issue by changing the version of guava dependency in pom.xml to 23.0.

If it is still not working for you, try changing the version of gson dependency in pom.xml to 2.8.2 or 2.8.5.

<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>23.0</version>
</dependency>

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.2</version>
</dependency>

<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.8.5</version>
</dependency>
Drobman answered 23/12, 2022 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.