Exception when running ChromeDriver with WebDriverManager in maven project - maven

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.

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.

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>

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.

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>

Related

what package should be imported when using #Before #After cucumber Hooks

I'm using Cucumber and Junit for my Maven Project. When I tried to create Cucumber Hooks with #After or #Before annotation and imported cucumber.api.java.Before; package, it didnt work. It says this is deprecated. Can someone tell me what annotation I can use for running the steps before every scenario or if I should import any other package for cucumber hooks? I tried importing io.cucumber.junit.CucumberOptions as well. It didn't work.
I'm using io.cucumber dependencies version 4.8.1. With this version, it shows #After #Before cucumber hooks annotation deprecated but With version 2.0.0,it doesn't show deprecated.
Could someone help on this.
Adapt your imports' packages. There is:
cucumber.api.java.After which is deprecated
io.cucumber.java.After which is not
The same applies to Before.
You need to add below dependency in POM.xml file
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>${cucumber.version}</version>
<scope>test</scope>
</dependency>
Import below packages:
import io.cucumber.java.After;
import io.cucumber.java.Before;

import of amqp from org.springframework get error

I'm working on existing Scala project which using the spring framework and I need to import org.springframework.amqp but when I tried to build the project I get:
Error:(15, 28) object amqp is not a member of package
org.springframework import org.springframework.amqp
It is really strange since I can see it in the formal website and I can see it in lot of examples in the web.
Any idea what is the problem?
A Maven dependency was missing. This is what I was need to add:
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-amqp</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>

Maven dependency conflicts

I am trying to resolve dependency version conflicts while using the below dependencies.
The worst one I am facing is zucchini project supports the apache commons-io versions from 1.4 to latest one. It does not support versions
below 1.4
and at the same time pagerduty-client supports commons-io versions below 1.4 version.
So It is not possible to specify a common version of this dependency (dependency management)
which supports in both zucchini and pager-duty client (both are third party libraries).
In this particular situation I couldn't find a possible way to resolve this issue. Any help will be appreciated.
<dependency>
<groupId>com.comcast.zucchini</groupId>
<artifactId>zucchini</artifactId>
<version>[2.2.5,)</version>
</dependency>
<dependency>
<groupId>com.github.dikhan</groupId>
<artifactId>pagerduty-client</artifactId>
<version>3.0.2</version>
</dependency>
Possibility 1
If the old and new commons-io package/class names are a close enough match, excluding the old dependency from pagerduty-client could possibly work.
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
<dependency>
<groupId>com.github.dikhan</groupId>
<artifactId>pagerduty-client</artifactId>
<version>3.0.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
This relies on the binary API of commons-io between versions 1.3.2 and 2.x being similar enough.
There does seem to be lots of overlap, looking at the code of each version:
https://github.com/apache/commons-io/tree/commons-io-1.3.2/src/java/org/apache/commons/io
https://github.com/apache/commons-io/tree/commons-io-2.5/src/main/java/org/apache/commons/io
Possibility 2
Split up your application so that the commons-io dependency is not shared and does not conflict.
It could be that the pagerduty-client and zucchini parts of your application do not need to be 'bundled' together, so split them up.
If they do need work together then you could still have two apps/processes and send messages between them.
Note
I cloned the pagerduty-client repo and changed the commons-io dependency from org.apache.commons:commons-io:1.3.2 to commons-io:commons-io:2.5 and the tests worked, so maybe you can suggest to the project owner that they upgrade commons-io.
And looking at the code it seems commons-io is hardly used (one place, HttpApiServiceImpl.java):
\pagerduty-client>findstr /s /c:"commons" *.java
src\main\java\com\github\dikhan\pagerduty\client\events\domain\AcknowledgeIncident.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\Incident.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\Incident.java:import org.apache.commons.lang3.builder.Builder;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\Payload.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\domain\ResolveIncident.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\HttpApiServiceImpl.java:import org.apache.commons.io.IOUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\PagerDutyEventsClient.java:import org.apache.commons.lang3.StringUtils;
src\main\java\com\github\dikhan\pagerduty\client\events\utils\FakePagerDutyEventsClient.java:import org.apache.commons.lang3.StringUtils;
As your commons-io is the problem you'll have to look further up the line. That means either upgrade pagerduty-client to a version that uses a newer version of commons-io that Cucumber likes, or downgrade zucchini to require a version of Cucumber that works with pagerduty-client as well.
This is a common problem with some jakarta commons packages, they at some point decided to massively change the public interface without changing the package name, causing conflicts like this for users.
You may be in luck, I once worked on a project where we had to rewrite thousands of lines of code just so we could link to a library we desperately needed that depended on a newer version of commons-io than the one we'd been using.

Maven: The type cannot be resolved. It is indirectly referenced from required .class files

I changed some existing projects from ant to maven projects.
So far so good.
All projects do have the same groupId.
Theres a project with name "ServerBase" and artifactId "server-base".
Within this project theres an abstract class "BaseService" which defines a logger via:
import org.jboss.logging.Logger;
[...]
protected Logger log = Logger.getLogger(this.getClass());
Theres another project with name "Server" and artifactId "server".
Within this project theres a class ConfigurationDAOImpl extending the BaseService-Class above.
Within ConfigurationDAOImpl the logger log is used for creating some outputs.
Within the "Server"'s POM file I have declared:
<dependency>
<groupId>com.tcom.amadeus</groupId>
<artifactId>server-base</artifactId>
<version>${project.version}</version>
</dependency>
Under BuildPath the dependency is shown very nice under MavenDependencies. I removed the old dirct/natural/ant-dependency from build path before.
If I remove it I am getting very much errors about missing classes etc.
But although I do have this dependency I am getting the followin error in eclipse (under tab markers):
The type org.apache.commons.logging.Log cannot be resolved. It is indirectly referenced from required .class files
Resource: ConfigurationDAPImpl.java
Path: /Server/src/main/...
Location: Line 24
Type: Java Problem
I tried removing the dependency and add it again but without any luck.
Both projects do refer to JAVA 1.8.
Both projects have been build with targets clean an package multiple times.
Both projects have been updated by Righclick or pressing F5.
I am using Eclipse Version: Neon.1a Release (4.6.1)
I am using apache-maven-3.3.9
I am using m2e Plugin.
Any further help would be grateful.
Thanks in advance.
There are two ways to 'solve' this:
1)
explicitly add the required dependency within the server-projects pom-file:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
2)
change the scop of the required dependency within the server-base-projects pom file from up to now 'provide' to 'compile' or erase the scope tag at all such that the default scope is used by maven (which I guess is 'compile')
old:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
new:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope></scope>
</dependency>
or:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
Some background to this from documentation:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies
provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example,
when building a web application for the Java Enterprise Edition, you
would set the dependency on the Servlet API and related Java EE APIs
to scope provided because the web container provides those classes.
This scope is only available on the compilation and test classpath,
and is not transitive.
Thanks all.
It looks like apache logging library is not brought transitively from your server-base project. Check if in project server under MavenDependencies you see commons-logging (apache logging) jar. If not, then add this as your maven dependency in server-base project.
Repeat the above for all jars that server-base depends on.

How to add maven modules to IntelliJ?

IntelliJ cannot find the classes in a Maven module, even if I add the jar dependency into pom.xml.
I created a Maven module: test-intellij . And then I created a class TestApp and made it implements ApplicationContextAware as below:
public class TestApp implements ApplicationContextAware{
}
IntelliJ told me: "can not find class ApplicationContextAware".
So I pressed "alt + enter", then from the popup tips I chose "Add maven dependency".
After this operation, the dependency below was added into pom.xml successfully:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
But when I try to import the ApplicationContextAware class , IntelliJ still cannot find the ApplicationContextAware class to import.
Could anybody help me to solve this issue?
Try to Reimport the Maven project using the corresponding button in IntelliJ IDEA Maven Projects tool window. Wait until the dependency is downloaded and indexing is complete. File | Invalidate Caches may also help.
Also check that you are using the latest IDEA version (12.0.2 at the moment). You should be able to browse inside the downloaded dependency jar in the Project View, External Libraries node.

Resources