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
我在 AWS windows 上安装了 selenium node 并启动了它。我在 AWS Linux 上设置了 Jenkins、git、Seleniuim hub。当我在 Jenkins 上构建应用程序时,selenium hub 正在尝试使用 私有 IP 地址 连接到 AWS windows 的 selenium 节点。我收到以下异常:
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:\Users\Administrator>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。
一个快速的解决方案是更改:
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.driver 和 chromedriver.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()
循环,因为您混淆了 Windows 和 Linux System.setProperty()
行中的样式如下:
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");
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
也许您正在使用办公电脑在节点和集线器之间进行交易。
在某种程度上,您可以从办公室计算机 <=> github <=> AWS EC2 控制台推送您的代码。
但将其注册为节点/集线器并尝试执行测试用例可能是不可能的。
请尝试使用相同环境的服务器。
这可能是你的ip不匹配导致的。我遇到了同样的错误,我发现我的机器有两个 IPv4 地址。一个是以太网,另一个是无线局域网。
步骤:
- 断开 Wi-Fi。
- 使用命令:
ipconfig
查看我的 IPv4 地址(那里只有一个 IP)。
- 只有一个 IP,它应该可以正确创建会话。
我在 AWS windows 上安装了 selenium node 并启动了它。我在 AWS Linux 上设置了 Jenkins、git、Seleniuim hub。当我在 Jenkins 上构建应用程序时,selenium hub 正在尝试使用 私有 IP 地址 连接到 AWS windows 的 selenium 节点。我收到以下异常:
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:\Users\Administrator>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。
一个快速的解决方案是更改:
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.driver 和 chromedriver.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()
循环,因为您混淆了 Windows 和 Linux System.setProperty()
行中的样式如下:
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");
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
也许您正在使用办公电脑在节点和集线器之间进行交易。
在某种程度上,您可以从办公室计算机 <=> github <=> AWS EC2 控制台推送您的代码。 但将其注册为节点/集线器并尝试执行测试用例可能是不可能的。
请尝试使用相同环境的服务器。
这可能是你的ip不匹配导致的。我遇到了同样的错误,我发现我的机器有两个 IPv4 地址。一个是以太网,另一个是无线局域网。 步骤:
- 断开 Wi-Fi。
- 使用命令:
ipconfig
查看我的 IPv4 地址(那里只有一个 IP)。 - 只有一个 IP,它应该可以正确创建会话。