当前位置: 首页 > 知识库问答 >
问题:

SessionNotCreatedException:无法启动新会话。可能的原因是远程服务器地址无效或浏览器启动失败

楚钊
2023-03-14

后我Chrome版本更新到96.0.4664.55我不能运行我的硒脚本和得到以下错误

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Starting ChromeDriver 96.0.4664.45 (76e4c1bb2ab4671b8beba3444e61c0f17584b2fc-refs/branch-heads/4664@{#947}) on port 59212
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.0.0', revision: '3a21814679'
System info: host: 'surajs-MacBook-Pro', ip: 'fe80:0:0:0:41a:d2c0:b272:42e6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '14.0.2'
Driver info: org.openqa.selenium.chrome.ChromeDriver

我正在使用WebDriverManager。chromedriver()。设置();

我看到chromedriver的版本是45,我的浏览器是96.0.4664.55。这是导致此问题的原因吗。我试图搜索55版本的驱动程序,但找不到https://chromedriver.chromium.org/downloads

我试着使用这个系统。setproperty也是,但没有帮助。

另外,当我尝试在Firefox上运行时,我也遇到了类似的错误。我想我错过了什么。看起来这不是驱动程序兼容性的问题

我正在使用Mac Big Sur,第一次尝试安装我的笔记本电脑

<dependencies>

        <dependency>
            <groupId>com.perfecto.reporting-sdk</groupId>
            <artifactId>reportium-java</artifactId>
            <version>2.3</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>7.0.0</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>tech.grasshopper</groupId>
            <artifactId>extentreports-cucumber7-adapter</artifactId>
            <version>1.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.1.0</version>
        </dependency>

        <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.6.0</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.8.1</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.78</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>7.0.0</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>klov-reporter</artifactId>
            <version>5.0.9</version>
        </dependency>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.0.3</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-gherkin</artifactId>
            <version>7.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.github.stephenc.monte</groupId>
            <artifactId>monte-screen-recorder</artifactId>
            <version>0.7.7.0</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-plugin</artifactId>
            <version>7.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>7.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>7.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>5.0.9</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>7.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.sikulix</groupId>
            <artifactId>sikulixapi</artifactId>
            <version>2.0.5</version>
        </dependency>
    </dependencies>

以下是firefox执行的错误

ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
1637917569509   geckodriver INFO    Listening on 127.0.0.1:51610
1637917569864   mozrunner::runner   INFO    Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "--marionette" "--remote-debugging-port" "63440" "-foreground" "-no-remote" "-profile" "/var/folders/kx/44qdbmdn3795n2fzm5vp1hnc0000gq/T/rust_mozprofile0FFbwE"
1637917570911   Marionette  INFO    Marionette enabled
2021-11-26 14:36:12.089 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSButton: 0x12f647c00>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2021-11-26 14:36:12.090 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSButton: 0x12f64a400>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2021-11-26 14:36:12.091 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSButton: 0x12f947000>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2021-11-26 14:36:12.092 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSButton: 0x12f943800>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2021-11-26 14:36:12.093 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSButton: 0x12f946400>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2021-11-26 14:36:12.094 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSPopoverTouchBarItemButton: 0x12f941400>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
2021-11-26 14:36:12.095 firefox-bin[83837:785689] Warning: Expected min height of view: (<NSPopoverTouchBarItemButton: 0x12f948400>) to be less than or equal to 30 but got a height of 32.000000. This error will be logged once per view in violation.
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at /var/folders/kx/44qdbmdn3795n2fzm5vp1hnc0000gq/T/rust_mozprofile0FFbwE/search.json.mozlz4", (void 0)))
console.error: BackgroundUpdate: 
  _reasonsToNotScheduleUpdates: Failed to check for Maintenance Service Registry Key: [Exception... "Component returned failure code: 0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIUpdateProcessor.getServiceRegKeyExists]"  nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"  location: "JS frame :: resource://gre/modules/BackgroundUpdate.jsm :: _reasonsToNotScheduleUpdates :: line 243"  data: no]
DevTools listening on ws://localhost:63440/devtools/browser/08ad3017-958d-4940-8397-d2caa02f1793
1637917573985   Marionette  INFO    Listening on port 60771
1637917574896   RemoteAgent WARN    TLS certificate errors will be ignored for this session
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.0.0', revision: '3a21814679'
System info: host: 'surajs-MacBook-Pro', ip: 'fe80:0:0:0:41a:d2c0:b272:42e6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '14.0.2'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {profile: UEsDBBQACAgIAIR0elMAAAAAAAA...}}], desiredCapabilities=Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {profile: UEsDBBQACAgIAIR0elMAAAAAAAA...}}}]
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:577)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:246)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:168)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:198)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
    at com.peopleGrove.stepDefinitions.BaseStepDefinitions.setDriver(BaseStepDefinitions.java:129)
    at com.peopleGrove.stepDefinitions.BaseStepDefinitions.beforeScenario(BaseStepDefinitions.java:72)
    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:564)
    at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
    at io.cucumber.java.Invoker.invoke(Invoker.java:24)
    at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
    at io.cucumber.java.JavaHookDefinition.execute(JavaHookDefinition.java:64)
    at io.cucumber.core.runner.CoreHookDefinition.execute(CoreHookDefinition.java:46)
    at io.cucumber.core.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:21)
    at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
    at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:86)
    at io.cucumber.core.runner.TestStep.run(TestStep.java:57)
    at io.cucumber.core.runner.TestCase.run(TestCase.java:89)
    at io.cucumber.core.runner.Runner.runPickle(Runner.java:75)
    at io.cucumber.testng.TestNGCucumberRunner.lambda$runScenario$1(TestNGCucumberRunner.java:132)
    at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$3(CucumberExecutionContext.java:110)
    at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
    at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:110)
    at io.cucumber.testng.TestNGCucumberRunner.runScenario(TestNGCucumberRunner.java:129)
    at io.cucumber.testng.AbstractTestNGCucumberTests.runScenario(AbstractTestNGCucumberTests.java:35)
    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:564)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
    at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
    at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
    at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
    at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
    at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.RuntimeException: NettyHttpHandler request execution error
    at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:83)
    at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
    at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
    at org.openqa.selenium.remote.http.netty.NettyHttpHandler.execute(NettyHttpHandler.java:51)
    at org.openqa.selenium.remote.http.AddSeleniumUserAgent.lambda$apply$0(AddSeleniumUserAgent.java:42)
    at org.openqa.selenium.remote.http.Filter.lambda$andFinally$1(Filter.java:56)
    at org.openqa.selenium.remote.http.netty.NettyClient.execute(NettyClient.java:119)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:84)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:62)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:139)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559)
    ... 42 more
Caused by: java.util.concurrent.ExecutionException: java.lang.ClassNotFoundException: io.netty.handler.codec.compression.Brotli
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2086)
    at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:206)
    at org.openqa.selenium.remote.http.netty.NettyHttpHandler.makeCall(NettyHttpHandler.java:66)
    ... 55 more
Caused by: java.lang.ClassNotFoundException: io.netty.handler.codec.compression.Brotli
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at io.netty.handler.codec.http.HttpContentDecompressor.newContentDecoder(HttpContentDecompressor.java:70)
    at io.netty.handler.codec.http.HttpContentDecoder.decode(HttpContentDecoder.java:100)
    at io.netty.handler.codec.http.HttpContentDecoder.decode(HttpContentDecoder.java:47)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:88)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:321)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:308)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:422)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:276)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:719)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    ... 1 more

共有3个答案

太叔志尚
2023-03-14

如果您的代码机和驱动程序机不同,我们不应该使用

WebDriverManager.chromedriver().setup();

这是行不通的。

我们应该使用选项和远程驱动程序

ChromeOptions options = new ChromeOptions();
options.addArguments("--window-position=0,0");
options.addArguments("--window-size=1840,1080");
options.addArguments("--no-sandbox");
options.addArguments("--disable-gpu");
options.addArguments("--headless");
driver = new RemoteWebDriver(new URL("http://xxxxxx:4444/wd/hub"), options);
郗学
2023-03-14

@Jayanth Bala我通过jenkins在Perfecto、Browserstack remote Environment上运行时也面临类似问题

private ThreadLocal<WebDriver> driver = new ThreadLocal<WebDriver>();
    
                ChromeOptions options1 = new ChromeOptions();
                options1.addArguments("use-fake-device-for-media-stream");
                options1.addArguments("use-fake-ui-for-media-stream");
                options1.addArguments("force-device-scale-factor=1.25");
                options1.addArguments("high-dpi-support=1.25");
    
     
                
                LoggingPreferences logPrefs = new LoggingPreferences();
                logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
   
    
                Map<String, Object> resourceArgs = new HashMap<>();
                resourceArgs.put("timeout", 120);
                String[] timezone = new String[] { "India Standard Time" };
                resourceArgs.put("newtimezone", timezone);
    
                options1.setCapability("goog:loggingPrefs", logPrefs);
                options1.setCapability("customizationScript", "pm-change-tz.yml");
                options1.setCapability("customizationScriptArgs", resourceArgs);
                options1.setCapability("platformName", "Windows");
                options1.setCapability("platformVersion", "10");
                options1.setCapability("browserName", "Chrome");
                options1.setCapability("browserVersion", "96");
                options1.setCapability("location", "US East");
                options1.setCapability("resolution", "1920x1080");
                options1.setCapability("waitForAvailableLicense", true);
                options1.setCapability("scriptName", scenario.getName());
                options1.setCapability("securityToken", Constants.perfectoAccessKey);
                options1.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
                options1.setCapability("download.default_directory", Constants.currentDirectoryPath + "\\downloads");
                HashMap<String, Object> chromePreference = new HashMap<>();
                chromePreference.put("credentials_enable_service", false);
                chromePreference.put("profile.password_manager_enabled", false);
                options1.setExperimentalOption("prefs", chromePreference);
    
                Thread.sleep(10000);
                driver.set(new RemoteWebDriver(new URL("https://peoplegrove-public.perfectomobile.com/nexperience/perfectomobile/wd/hub"), (Capabilities)options1));
                Thread.sleep(10000);

在驱动程序上。set line I randamonly得到与上述相同的错误。我的套件中有140个案例,在运行了10-15-20个案例后,它开始出现这个错误。你能找出能力方面的任何问题吗??

使用相同的selenium4.0.0

阎嘉荣
2023-03-14

@jayanth Bala@djmonki感谢您的关注。

我的问题已得到解决。

问题在于

        <dependency>
            <groupId>com.sikulix</groupId>
            <artifactId>sikulixapi</artifactId>
            <version>2.0.5</version>
        </dependency>

当我把它降到2.0.4的时候,我现在的设置没有问题。看起来sikuli的最新版本与上述代码中使用的cucumber/javaclient/junit-jar都不兼容。

 类似资料: