SeleniumHQ / selenium

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

[🐛 Bug]: ...package...config.SeleniumConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException #14124

Closed iamrdb2f closed 1 week ago

iamrdb2f commented 2 weeks ago

What happened?

Hello, exact error I am facing using Selenium to run run remote test with Jenkins is:

config.SeleniumConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'setupDriver' threw exception; nested exception is org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Error forwarding the new session Empty pool of VM for setup Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}} 
Host info: host: '501ab6eeb333', ip: '172.17.0.3'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.114.2.el7.x86_64', java.version: '11.0.4.0.101'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}}]}]
Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:417)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:119)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
    at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:65)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:381)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:319)
    at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
    at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)

How can we reproduce the issue?

WebDriver is set by this function in remote environment:

 //Driver to run on Jenkins
    public WebDriver webDriver() {

        //Users must set the proxy to access Selenium

        System.setProperty(proxyHostLabel, proxyHost);
        System.setProperty(proxyPortLabel, proxyPort);

        try {
            ChromeOptions options = new ChromeOptions();

            HashMap<String, Object> chromePrefs = new HashMap<>();
            chromePrefs.put("plugins.always_open_pdf_externally", true);
            chromePrefs.put("profile.default_content_settings.popups", 0);

            options.setExperimentalOption("prefs", chromePrefs);
            options.setScriptTimeout(Duration.ofMinutes(15)); //Defaulting to 15 minutes Timeout rule
            options.setPageLoadTimeout(Duration.ofMinutes(15));//Defaulting to 15 minutes Timeout rule
            options.addArguments("start-maximized");
            options.addArguments("enable-automation");
            options.addArguments("--no-sandbox");
            options.addArguments("--disable-infobars");
            options.addArguments("--disable-dev-shm-usage");
            options.addArguments("--disable-browser-side-navigation");
            options.addArguments("--disable-gpu");

            return new RemoteWebDriver(new URL(Objects.requireNonNull(seleniumHuburl)), options);
        } catch (MalformedURLException e) {
            LOG.error("Invalid Selenium Hub URL", e);
        }

        return null;
    }

I use a Jenkinsfile launching a Build stage designed as bellow:

        stage('Build: Launch tests') {
            agent {
                docker {
                    image '$IMG_MAVEN'
                    label 'generic-slave'
                    reuseNode true
                }
            }
            steps {

                sh 'mvn -P ALL test -Denv=bench -Dremote=yes'
                sh 'mvn allure:report'

            }
        }

### Relevant log output

```shell
So, when I run the Job from Jenkins, this is where I get this error:

config.SeleniumConfig: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.openqa.selenium.WebDriver]: Factory method 'setupDriver' threw exception; nested exception is org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Error forwarding the new session Empty pool of VM for setup Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}} 
Host info: host: '501ab6eeb333', ip: '172.17.0.3'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.114.2.el7.x86_64', java.version: '11.0.4.0.101'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}}]}]
Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:417)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:119)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:248)
    at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.springTestContextPrepareTestInstance(AbstractTestNGSpringContextTests.java:149)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:65)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:381)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:319)
    at org.testng.internal.invokers.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
    at org.testng.internal.invokers.TestMethodWorker.run(TestMethodWorker.java:122)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)


### Operating System

Linux, os.arch: 'amd64', os.version: '3.10.0-1160.114.2.el7.x86_64

### Selenium version

Build info: version: '4.11.0', revision: '040bc5406b'

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

Chrome is the WebDriver. Main question and problem that I have is that logs don't say anything about the chrome version. And this makes it even harder to know what is going. Because I could had at least tried to update to chromedriver version to the corresponding one of chrome browser

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

ChromeDriver - Version 124.0.6367.207 (Linux)

### Are you using Selenium Grid?

_No response_
github-actions[bot] commented 2 weeks ago

@iamrdb2f, 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!

iamrdb2f commented 2 weeks ago

Hello, does anyone know something about this error?

iamrdb2f commented 1 week ago

I am still having this:

Caused by: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Error forwarding the new session Empty pool of VM for setup Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}} Host info: host: '5c0711e30a37', ip: '172.17.0.3' Build info: version: '4.11.0', revision: '040bc5406b' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-1160.114.2.el7.x86_64', java.version: '11.0.4.0.101' Driver info: org.openqa.selenium.remote.RemoteWebDriver Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}}]}] Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*, start-maximized, enable-automation, --no-sandbox, --disable-infobars, --disable-dev-shm-usage, --disable-browser-side-navi..., --disable-gpu], extensions: [], prefs: {plugins.always_open_pdf_externally: true, profile.default_content_settings.popups: 0}}, timeouts: {pageLoad: 900000, script: 900000}} at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:96) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163) at org.openqa.selenium.remote.TracedCommandExecutor.execute(TracedCommandExecutor.java:51) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:159) at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:139) at com.natixis.tradego.nrt.config.SeleniumConfig.webDriver(SeleniumConfig.java:173) at com.natixis.tradego.nrt.config.SeleniumConfig.setupDriver(SeleniumConfig.java:96) at

titusfortner commented 1 week ago

It looks like you are sending a session request to a hub that does not have any attached nodes. You can start it in standalone mode if you do not need multiple nodes. Please see our Grid Documentation, and feel free to ask more questions at the links provided below.

github-actions[bot] commented 1 week ago

💬 Please ask questions at: