WebDriverException:转发新会话时出错 转发请求时出错 连接到 my_ip:5555 [/my_ip] 失败:连接超时 [英] WebDriverException: Error forwarding the new session Error forwarding the request Connect to my_ip:5555 [/my_ip] failed: Connection timed out

查看:14
本文介绍了WebDriverException:转发新会话时出错 转发请求时出错 连接到 my_ip:5555 [/my_ip] 失败:连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 AWS windows 上安装了 selenium node 并启动了它.我在 AWS Linux 上设置了 Jenkins、git、Selenuim 集线器.当我在 Jenkins 上构建应用程序时,selenium hub 正尝试使用私有 IP 地址连接到 AWS windows 的 selenium 节点.我收到以下异常:

I installed selenium node on AWS windows and started it. And I setup Jenkins, git, Seleniuim hub on AWS Linux. When i'm building app on Jenkins, selenium hub is trying to connect to selenium node of AWS windows with private IP address. And i'm getting following exception:

org.openqa.selenium.WebDriverException: 
Error forwarding the new session Error forwarding the request Connect to windows_private_ip:5555 [/windows_private_ip] failed: Connection timed out (Connection timed out)
Command duration or timeout: 190.25 seconds
Build info: version: '3.5.1', revision: '9c21bb67ef', time: '2017-08-17T15:26:08.955Z'
System info: host: 'some_host_name', ip: 'some_ip', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.76-3.78.amzn1.x86_64', java.version: '1.8.0_151'
Driver info: driver.version: RemoteWebDriver
Caused by: org.openqa.grid.common.exception.GridException: Error forwarding the new session Error forwarding the request Connect to windows_private_ip:5555 [/windows_private_ip] failed: Connection timed out (Connection timed out)

网格节点命令:

C:UsersAdministrator>java -Dwebdriver.chrome.driver=./drivers/windows-driver/chromedriver.exe -jar C:\Users\Administrator\Desktop\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register

我的代码是:

if (browser.equalsIgnoreCase("FF")) {
            System.setProperty("webdriver.gecko.driver", "drivers/windows-driver/geckodriver.exe");
            DesiredCapabilities cap = DesiredCapabilities.firefox();
            // Set the platform where we want to run our test- we can use
            // MAC and Linux and other platforms as well
            cap.setPlatform(Platform.ANY);
            cap.setCapability("gecko", true);
            // Here you can use hub address, hub will take the
            // responsibility to execute the test on respective node
            URL url = new URL("http://hub_public_ip:4444/wd/hub");
            // Create driver with hub address and capability
            gbb = PageFactory.initElements(new RemoteWebDriver(url, cap), GuruBase.class);
        } else if (browser.equalsIgnoreCase("IE")) {
            System.setProperty("webdriver.ie.driver", "drivers/windows-driver/IEDriverServer.exe");
            gbb = PageFactory.initElements(new InternetExplorerDriver(), GuruBase.class);

        } else if (browser.equalsIgnoreCase("GC")) {
            System.setProperty("webdriver.chrome.driver", "drivers/windows-driver/chromedriver.exe");
            ChromeOptions cho = new ChromeOptions();
            cho.addArguments("disabled-extensions");
            cho.addArguments("--start-maximized");
            gbb = PageFactory.initElements(new ChromeDriver(cho), GuruBase.class);
        }

        else if (browser.equalsIgnoreCase("html")) {
            gbb = PageFactory.initElements(new HtmlUnitDriver(true), GuruBase.class);
        }

我在 Jenkins 上运行 selenium hub.

I'm running selenium hub on Jenkins.

推荐答案

一个快速的解决方案是改变:

A quick solution will be to change :

java -Dwebdriver.gecko.driver=./drivers/windows-driver/chromedriver.exe -jar C:\Users\Administrator\Desktop\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register

当您使用 Dwebdriver.gecko.driverchromedriver.exe

至:

  • 使用 GeckoDriver :

java -Dwebdriver.gecko.driver=./drivers/windows-driver/geckodriver.exe -jar C:\Users\Administrator\Desktop\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register

  • 使用 Chromedriver :

    java -Dwebdriver.chrome.driver=./drivers/windows-driver/chromedriver.exe -jar C:\Users\Administrator\Desktop\selenium-server-standalone-3.0.1.jar -role node -hub http://ip_address:4444/grid/register
    

  • 此外,您需要检查 if() 循环,因为 WindowsLinux 样式在 System.setProperty() 行如下:

    Additionally, you need to check your if() loop as you have a mixed up representation of Windows and Linux styles in System.setProperty() line as follows :

    • GeckoDriver :

    System.setProperty("webdriver.gecko.driver", "drivers/windows-driver/geckodriver.exe");
    

  • ChromeDriver :

    System.setProperty("webdriver.chrome.driver", "drivers/windows-driver/chromedriver");
    

  • IEDriverServer :

    System.setProperty("webdriver.ie.driver", "drivers/windows-driver/IEDriverServer.exe");
    

  • 注意:在 Windows 系统上,您需要提及扩展名 .exe 部分,例如geckodriver.exeLinux 系统 上,您需要去掉扩展名 .exe 部分,例如chromedriver

    Note : On Windows Systems you need to mention the extension .exe part e.g. geckodriver.exe while on Linux Systems you need strip off the extension .exe part e.g. chromedriver

    这篇关于WebDriverException:转发新会话时出错 转发请求时出错 连接到 my_ip:5555 [/my_ip] 失败:连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆