SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.55k stars 8.16k forks source link

[🐛 Bug]: Not possible to test with chromedriver #13867

Closed bennipalmhert closed 5 months ago

bennipalmhert commented 6 months ago

What happened?

I have implemented a basic JUnit 5 testing class, where i want to test functions of my Maven Project. Before all test I set the system properties for webdriver.chrome.driver and webdriver.http.factory, before each test i initialise a new Chromedriver. Inside my test I get the url for my driver. After starting up my web application I execute my tests, but all tests fail and i get an error message for the test class (java.lang.NoSuchMethodError: 'javax.net.ssl.SSLContext org.openqa.selenium.remote.http.ClientConfig.sslContext()').

I imported the dependencies selenium-java, selenium-chrome-driver and also webdrivermanager to my pom.XML

How can we reproduce the issue?

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class NavigationPageTest {

    private WebDriver driver;

    @BeforeAll
    static void setUp() {
        System.setProperty("webdriver.chrome.driver", "./chromedriver");
        System.setProperty("webdriver.http.factory", "jdk-http-client");
    }

    @BeforeEach
    void setup() {
        driver = new ChromeDriver();
    }

    @Test
    void navigateToHome() {

    }

    @Test
    void navigateToAbout() {

    }

    @AfterEach
    void tearDown() {
        driver.quit();
    }
}

Relevant log output

java.lang.NoSuchMethodError: 'javax.net.ssl.SSLContext org.openqa.selenium.remote.http.ClientConfig.sslContext()'

    at org.openqa.selenium.remote.http.jdk.JdkHttpClient.<init>(JdkHttpClient.java:149)
    at org.openqa.selenium.remote.http.jdk.JdkHttpClient$Factory.createClient(JdkHttpClient.java:476)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:107)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:94)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:85)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:80)
    at org.openqa.selenium.chromium.ChromiumDriverCommandExecutor.<init>(ChromiumDriverCommandExecutor.java:35)
    at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.<init>(ChromeDriver.java:118)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
    at at.ac.uibk.estore.selenium.NavigationPageTest.setup(NavigationPageTest.java:28)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

java.lang.NoSuchMethodError: 'javax.net.ssl.SSLContext org.openqa.selenium.remote.http.ClientConfig.sslContext()'

    at org.openqa.selenium.remote.http.jdk.JdkHttpClient.<init>(JdkHttpClient.java:149)
    at org.openqa.selenium.remote.http.jdk.JdkHttpClient$Factory.createClient(JdkHttpClient.java:476)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:107)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:94)
    at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:85)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:80)
    at org.openqa.selenium.chromium.ChromiumDriverCommandExecutor.<init>(ChromiumDriverCommandExecutor.java:35)
    at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.<init>(ChromeDriver.java:118)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
    at at.ac.uibk.estore.selenium.NavigationPageTest.setup(NavigationPageTest.java:28)
    at java.base/java.lang.reflect.Method.invoke(Method.java:580)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)

Process finished with exit code 255

Operating System

macOS Sonoma Version 14.4.1 on mac-arm64 (M1)

Selenium version

Java 4.19.1

What are the browser(s) and version(s) where you see this issue?

Chrome 123.0.6312.124

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 123.0.6312.122

Are you using Selenium Grid?

No

github-actions[bot] commented 6 months ago

@bennipalmhert, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

krmahadevan commented 6 months ago

@bennipalmhert - Please show us what your <dependencies> looks like

bennipalmhert commented 6 months ago

@krmahadevan These are the selenium dependencies i added:

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.19.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>4.19.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.8.0</version>
</dependency>

and these are all dependencies in my pom.XML:
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>4.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.10.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>5.10.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>5.11.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-junit-jupiter</artifactId>
            <version>5.10.0</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.19.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>4.19.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.8.0</version>
        </dependency>
</dependencies>
krmahadevan commented 6 months ago

@bennipalmhert - Can you please remove the following two dependencies and try again ?

You are getting this via selenium-java

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-chrome-driver</artifactId>
            <version>4.19.1</version>
        </dependency>

You don't need this anymore. This is internally taken care of by selenium

        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.8.0</version>
        </dependency>
diemol commented 6 months ago

It might also be an issue with springframework, as it embeds Selenium, and I think they always have an older version.

krmahadevan commented 6 months ago

Good point @diemol. I forgot that.

@bennipalmhert - Please check here https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html

bennipalmhert commented 6 months ago

@krmahadevan - I've removed the dependencies and reloaded maven project but still get the same error

krmahadevan commented 6 months ago

@bennipalmhert - You might want to try running the below commands to sort out your dependencies discrepancy

This will help you identify the problem in your dependencies

bennipalmhert commented 6 months ago

@krmahadevan - running the comand dependency:analyze leads to this warning:

org.seleniumhq.selenium:selenium-api:jar:4.14.1:compile
   org.springframework.data:spring-data-jpa:jar:3.2.2:compile
   org.springframework:spring-context:jar:6.1.3:compile
   org.springframework:spring-core:jar:6.1.3:compile
   org.springframework.boot:spring-boot:jar:3.2.2:compile
   com.fasterxml.jackson.core:jackson-databind:jar:2.15.3:compile
   org.springframework:spring-jdbc:jar:6.1.3:compile
   jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
   org.springframework:spring-beans:jar:6.1.3:compile
   org.springframework:spring-webmvc:jar:6.1.3:compile
   org.springframework:spring-web:jar:6.1.3:compile
   org.springframework.security:spring-security-core:jar:6.2.1:compile
   org.springframework.data:spring-data-commons:jar:3.2.2:compile
   org.springframework.security:spring-security-config:jar:6.2.1:compile
   org.springframework.security:spring-security-web:jar:6.2.1:compile
   org.springframework.boot:spring-boot-autoconfigure:jar:3.2.2:compile
   org.apache.tomcat.embed:tomcat-embed-core:jar:10.1.18:provided
   jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
   org.aspectj:aspectjweaver:jar:1.9.21:compile
   org.springframework:spring-tx:jar:6.1.3:compile
   org.seleniumhq.selenium:selenium-support:jar:4.14.1:compile
   org.springframework.boot:spring-boot-test:jar:3.2.2:test
   org.slf4j:slf4j-api:jar:2.0.11:compile
   com.fasterxml.jackson.core:jackson-core:jar:2.15.3:compile
   org.springframework.security:spring-security-crypto:jar:6.2.1:compile
   com.fasterxml.jackson.core:jackson-annotations:jar:2.15.3:compile
Unused declared dependencies found:
   org.springframework.boot:spring-boot-starter-web:jar:3.2.2:compile
   org.springframework.boot:spring-boot-devtools:jar:3.2.2:runtime
   org.projectlombok:lombok:jar:1.18.30:compile
   org.springframework.boot:spring-boot-starter-data-jpa:jar:3.2.2:compile
   org.springframework.boot:spring-boot-starter-tomcat:jar:3.2.2:provided
   org.springframework.boot:spring-boot-starter-test:jar:3.2.2:test
   org.springframework.boot:spring-boot-starter-security:jar:3.2.2:compile
   org.junit.jupiter:junit-jupiter-params:jar:5.10.2:test
   org.mockito:mockito-core:jar:5.11.0:test
   org.mockito:mockito-junit-jupiter:jar:5.10.0:test
   org.seleniumhq.selenium:selenium-java:jar:4.19.1:compile
Non-test scoped test only dependencies found:
   org.seleniumhq.selenium:selenium-chrome-driver:jar:4.19.1:compile

and running dependency:analyze-report shows me a build success, with no warning or error messages.

Does this mean i should downgrade my selenium-java version to 4.14.1?

krmahadevan commented 6 months ago

@bennipalmhert - Try adding a property like below and see if that helps

<properties>
    <selenium.version>4.19.1</selenium.version>
</properties>

You might want to spend sometime going through this page to help you learn how to fix this discrepancy

https://docs.spring.io/spring-boot/docs/current/reference/html/dependency-versions.html#appendix.dependency-versions.properties

diemol commented 5 months ago

I will close this, as we have seen the same issue in the past due to dependency conflicts.

github-actions[bot] commented 4 months ago

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.