3

I'm writing Selenium Junit tests with IntelliJ. The tests run ok if I trigger from test directly. However, if I trigger tests from TestRunnerSuite with JunitCore, I encountered following weird error that I did not find a solution after researching on google. Similar questions on DriverService$builder, but not my error type.

[main] ERROR sire.responseOrg.TestIncidents - java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:332)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
    at sire.responseOrg.util.util1.setupChromeDriver(util1.java:51)
    at sire.responseOrg.Test1.setUp(Test1.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at ......Omitted
    at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
    at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
    at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)

I'm using Selenium 3.5.3 and chrome 76.---> Updated to Selenium 3.141.59,and with main scope.
Now getting error

java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
    at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
    at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
    at sire.responseOrg.util.SeleniumUtil.setupChromeDriver(SeleniumUtil.java:62)
    at sire.responseOrg.TestIncidents.setUp(TestIncidents.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:24)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:136)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
    at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
    at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.http.auth.Credentials
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    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)
    ... 33 more

Full pom.xml dependencies

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>myGroupId</groupId>
    <artifactId>myArtifactId</artifactId>
    <version>1.0-SNAPSHOT</version>
    <description>My description</description>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/junit/junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>main</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>3.141.59</version>
            <scope>main</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>
            <scope>main</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.6</version>
            <scope>main</scope>
        </dependency>
        <dependency>
            <groupId>com.salesforce.seti</groupId>
            <artifactId>selenium-dependencies</artifactId>
            <version>1.0.3</version>
        </dependency>


    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.1.2</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>test-jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    <packaging>pom</packaging>

</project>

My project folder structure is

.src
...main
.....java
.......projectname
.........constantsFolder
.........utilFolder
...........util1.java
...........util2.java
.........Test1.java
.........TestRunnerSuite.java
.........WebDrivers.java

If I start test from Test1.java, the test runs regularly though with warnings

[main] INFO projectname.util.util1 - Set up chrome driver.
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590e025-refs/branch-heads/3770@{#1003}) on port 28755
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1566609934.853][WARNING]: This version of ChromeDriver has not been tested with Chrome version 76.
Aug 23, 2019 6:25:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[main] INFO projectname.util.util1 - Navigating to https://mytest.com/

However, after adding a testSuiteRunner as below.

@RunWith(Suite.class)
@Suite.SuiteClasses({ Test1.class })
public class TestSuiteRunner {
    public static void main(String[] args) {
        Result result = JUnitCore.runClasses(Test1.class);
        // print erros, exit etc omitted
    }
}

Now I get the weird error and cannot fire the chromedriver. The webdriver I have is singleton

public class WebDrivers {
    private static WebDriver driver = null;

    public static WebDriver getInstance(){
        if (driver == null) {
            driver = new ChromeDriver();
        }
        return driver;
    }
}

It's my first time to work on setting everything up from grounds. I'm not sure if it's pom dependency issue, singleton webdriver issue, or something else. Could anyone share an eyesight on this and give some clues? Much appreciated.

user2751691
  • 401
  • 2
  • 10
  • 32
  • As you are setting everything from ground. It better to update the selenium-java to 3.141.59 or Selenium 4-alpha, ChromeDriver 76.0.3809.126 and if possible use Junit 5 – Rahul L Aug 24 '19 at 07:28
  • @RahulL Hi, thanks for the reply. I updated selenium-java to 3.141.59, but no luck. – user2751691 Aug 25 '19 at 02:36
  • 1
    Can you post the full pom? It seems that the program cannot compile using the folder structure and program you provide.(Your classes are put under *main* folder but the dependency scope is *test*. – samabcde Aug 26 '19 at 06:06
  • Also check the 'guava' dependency that is being resolved. – Rahul L Aug 26 '19 at 07:50

4 Answers4

9

This error message...

java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;

...implies that there is some incompatibility between the version of the binaries you are using specifically with the guava dependency.

  • You are using chrome= 76.0
  • You are using the following:

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-chrome-driver</artifactId>
        <version>3.5.3</version>
        <scope>test</scope>
    </dependency>
    
  • Your Selenium Client version is 3.5.3 which is more then 2 years older.

  • Your JDK version is unknown to us.

So there is a clear mismatch between the Selenium Client v3.5.3 and Chrome Browser v76.0

However as per the discussions in:

These issues crop up due to incompatibile Guava dependency.

The current guava version used within selenium-java-3.141.59 is guava-25.0-jre


Solution

Ensure that:

  • JDK is upgraded to current levels JDK 8u222.
  • Selenium is upgraded to current levels Version 3.141.59.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Update

So presumably your main question with respect to the error:

java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;

is solved. Congratulations.

Now, as per your question update as you are seeing the error:

java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials

There are two aspects.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you very much for the detailed notes. I updated selenium package to 3.141.59, and changed scope to main. But no luck and getting auth credentials error now. I updated with the error message and full pom.xml file in description. Thank you very much for helping. – user2751691 Aug 26 '19 at 21:20
  • @user2751691 Checkout the updated answer and let me know if you need anything further. – undetected Selenium Aug 26 '19 at 21:53
2

Remove scope from your POM. test or main Isn't needed for your tests to run

kempster86
  • 39
  • 2
0

used this gauva jar with latest testng 7.3. Resolved this error also dont configure any testNG seperately. Please remove configuration if we add it in pom.xml

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33
0

I was facing the same issue. The following steps helped resolve it:

Go to your POM file and comment out/ remove the following dependency:

--> org.seleniumhq.selenium
--> selenium-java
--> 2.48.2

Check what version you have.
  1. Then copy the latest mvn dependency which is 4.1.1 as of now
  2. Perform mvn clean install (till this point it will be sufficient)
  3. Perform reload all maven projects
  4. Perform download sources
  5. Build your project again
  6. Play/ perform mvn clean install again

FYI: as per my knowledge, this issue occurs at compile time when you execute the code. Or the time when you execute a code in a new project which was compiled with different dependencies and versions earlier.