SessionNotCreatedException:无法创建新服务:Ubuntu 上带有 Selenium Grid 的 GeckoDriverService 无法驱动 Firefox

Posted

技术标签:

【中文标题】SessionNotCreatedException:无法创建新服务:Ubuntu 上带有 Selenium Grid 的 GeckoDriverService 无法驱动 Firefox【英文标题】:SessionNotCreatedException: Unable to create new service: GeckoDriverService with Selenium Grid on Ubuntu failing to drive Firefox 【发布时间】:2018-05-13 01:31:39 【问题描述】:

我无法使用 geckodriver 从 Selenium 驱动 Firefox。这很奇怪,因为 chrome 是用相同的框架驱动的,没有错误!

这些是我的版本号:

Firefox 54.0 (64-bit)
Chrome Version 62.0.3202.94 (Official Build) (64-bit)

selenium-server-standalone-3.7.1.jar
client-combined-3.5.3-nodeps.jar

geckodriver-v0.19.1-linux64
chromedriver_linux64 

Ubuntu 16.10

我从 Selenium webdriver with java 得到的错误如下:

--------------------------------Error:
leder@leder-VirtualBox:~/Source/SeleniumCheese/bin$ ./execute_grid.sh 
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-06T21:07:36.161Z'
System info: host: 'leder-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.8.0-59-generic', java.version: '1.8.0_131'
Driver info: driver.version: unknown
Command duration or timeout: 1.39 seconds
---------------------------------Schnapp

这是我的设置,firefox 坏了,chrome 没问题:

Grid_SetUp.java

package de.auticon.selenium_server;
import org.openqa.selenium.WebDriver;    
import org.openqa.selenium.By;   
import org.openqa.selenium.WebElement;   
import org.openqa.selenium.remote.DesiredCapabilities;    
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.MalformedURLException;    
import java.net.URL;

public class Grid_SetUp    
    public static WebDriver driver;

    public static void main(String[]  args) throws MalformedURLException, InterruptedException   
        System.setProperty("webdriver.chrome.driver","/opt/selenium/chromedriver");    
        String URL = "http://www.google.de";    
        String Node = "http://192.168.40.40:4444/wd/hub";    
        DesiredCapabilities cap = DesiredCapabilities.firefox();   
        driver = new RemoteWebDriver(new URL(Node), cap);
        driver.navigate().to(URL);
        WebElement element = driver.findElement(By.name("q"));
        //Enter something to search for
        element.sendKeys("Cheese!");
        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();
        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());

        Thread.sleep(5000);

        driver.quit();    
        

selenium_grid.sh:

#!/bin/bash
java -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role hub &
java -Dwebdriver.gecko.driver=/opt/selenium/geckodriver -jar /opt/selenium/selenium-server-standalone-3.7.1.jar -role webdriver -hub http://192.168.40.40:4444/grid/register -nodeConfig /opt/selenium/defaultNodeConfig.json -browser "browserName=firefox,platform=LINUX" &

execute_grid.sh:

#!/bin/bash
java -cp ".:/opt/selenium/selenium-server-standalone-3.7.1.jar" de.auticon.selenium_server.Grid_SetUp

我现在更新了工作配置的问题。但是当运行 firefox Selenium TC 时,TC 完成了,不幸的是,服务器以错误消息“会话未创建”结束:

13:49:10.376 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession@70c81601
13:49:10.381 INFO - To downstream: "value":"error":"session not created","message":"Tried to run command without establishing a connection","stacktrace":"stack backtrace:\n   0:           0x4edb3c - backtrace::backtrace::trace::hc4bd56a2f176de7e\n   1:           0x4edb72 - backtrace::capture::Backtrace::new::he3b2a15d39027c46\n   2:           0x4409a1 - webdriver::error::WebDriverError::new::h81babdd86c977032\n   3:           0x4280ea - <webdriver::server::Dispatcher<T, U>>::run::h2119c674d7b88193\n   4:           0x4029b9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h21d98a9ff86d4c25\n   5:           0x40be65 - std::panicking::try::do_call::h5cff0c9b18cfdbba\n   6:           0x5e6a6c - panic_unwind::__rust_maybe_catch_panic\n                        at /checkout/src/libpanic_unwind/lib.rs:99\n   7:           0x41eb22 - <F as alloc::boxed::FnBox<A>>::call_box::h413eb1d9d9f1c473\n   8:           0x5df13b - alloc::boxed::impl::call_once<(),()>\n                        at /checkout/src/liballoc/boxed.rs:692\n                         - std::sys_common::thread::start_thread\n                        at /checkout/src/libstd/sys_common/thread.rs:21\n                         - std::sys::imp::thread::impl::new::thread_start\n                        at /checkout/src/libstd/sys/unix/thread.rs:84"

【问题讨论】:

【参考方案1】:

关于Selenium Grid配置的几句话:

您将Test Bed 称为selenium-server-standalone-3.7.1.jarclient-combined-3.5.3-nodeps.jar。根据Best Practices,您应该使用以下任一不能同时使用

始终尝试使用最新发布的版本,即selenium-server-standalone-3.7.1.jar

selenium_grid.sh: 中,您需要更改以下内容:

java -Dwebdriver.gecko.driver=/opt/selenium/geckodriver

【讨论】:

谢谢你,DebanjanB!我可以毫无问题地忽略:/opt/selenium/client-combined-3.5.3-nodeps.jarjava -Dwebdriver.gecko.driver=/opt/selenium/geckodriver 现在运行良好! 我将问题更新为工作配置并添加了新的错误消息,请查看。 @DebanjanB 基于selenium.dev/downloads,最新版本是 3.141.59,我使用它但没有帮助。【参考方案2】:

我只是使用我的 firefox 浏览器、seleinum grid 和 eclipse 中的 Testng 来跟踪这段代码

System.setProperty("webdriver.gecko.driver","E:\\FireFoxDriver\\geckodriver.exe");    
    String URL = "http://demo.automationtesting.in/Register.html";    
    String Node = "http://192.168.43.97:4444/wd/hub";    
    DesiredCapabilities cap = DesiredCapabilities.firefox();   
    driver = new RemoteWebDriver(new URL(Node), cap);
    driver.get(URL);
    driver.manage().window().maximize();
    System.out.println("Page title is: " + driver.getTitle());

    Thread.sleep(5000);

    driver.close(); 

用于在本地机器上创建集线器 java -jar E:\SeleniumGrid\selenium-server-standalone-3.141.59.jar -role hub

打开 cmd 并输入上面下载 selenium 独立服务器的行 然后你会得到这两个

节点应该注册到http://192.168.43.97:4444/grid/register/ 客户端应该连接到http://192.168.43.97:4444/wd/hub

然后再次打开 cmd 并为 node 输入这个 java -Dwebdriver.gecko.driver="E:\FireFoxDriver\geckodriver.exe" -jar E:\SeleniumGrid\selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.43.97:4444/grid/register

【讨论】:

以上是关于SessionNotCreatedException:无法创建新服务:Ubuntu 上带有 Selenium Grid 的 GeckoDriverService 无法驱动 Firefox的主要内容,如果未能解决你的问题,请参考以下文章