环境:
节点和枢纽
start java -jar c:\users\powder aadin-testbench-standalone-4.1.0.jar -role hub
启动 java -jar c:\users\powder aadin-testbench-standalone-4.1.0.jar -role node -Dwebdriver.edge.driver=c:\users\powder\MicrosoftWebDriver.exe
Java代码中的用法
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName(DesiredCapabilities.edge().getBrowserName());
//DesiredCapabilities capabilities = DesiredCapabilities.edge(); Tried as well
capabilities.setCapability("acceptSslCerts", "true");
setDriver(new RemoteWebDriver(new URL(this.remoteHubUrl), capabilities));
getDriver().get("http://www.google.com");
错误信息
转发新会话时出错找不到:Capabilities [{acceptSslCerts=true, browserName=MicrosoftEdge}]
在其他浏览器上一切正常,但在 Edge 上却不行。有什么解决办法吗?
这里有2个问题:
首先,如果您查看默认节点配置,您会注意到默认情况下仅启用 Firefox、Chrome 和 IE(这就是为什么您需要使用它们的原因是通过系统属性指定驱动程序位置)。如果你想使用任何其他浏览器,那么你需要使用你自己的 json 配置:
{
"capabilities": [
{
"browserName": "MicrosoftEdge",
"platform": "WIN10",
"maxInstances": 1
},
{
"browserName": "firefox",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "chrome",
"platform": "WIN10",
"maxInstances": 5
},
{
"browserName": "internet explorer",
"platform": "WIN10",
"maxInstances": 1
}
],
"hub": "http://selenium-hub-host:4444"
}
并将其传递给您的命令行:
java "-Dwebdriver.edge.driver=c:\path\to\MicrosoftWebDriver.exe" "-Dwebdriver.gecko.driver=c:\path\to\geckodriver.exe" "-Dwebdriver.chrome.driver=c:\path\to\chromedriver.exe" "-Dwebdriver.ie.driver=c:\path\to\IEDriverServer.exe" -jar "c:\path\to\selenium-server-standalone.jar" -role node -nodeConfig "c:\path\to\the\above.json"
(顺便说一句:或者,您也可以使用多个
-capabilities
或 -browser
参数将整个配置放在命令行中)
这在理论上应该可行。然而在实践中,您经常会遇到第二个问题,即:“有时它随机不起作用”;] 最初一切看起来都很好:您的网格将在控制台上正确报告 Edge 浏览器功能,它将正确委托测试对于包含 Edge 的节点,该节点将正确启动 Edge 浏览器,但是浏览器有时会冻结在其带有 e 徽标的初始蓝屏上,几秒钟后您会在客户端收到一些异常,没有任何有意义的堆栈跟踪或消息(我没有把它保存在任何地方现在粘贴在这里)。
有些人建议 workaround 在同一台机器上启动 2 个单独的节点(当然在不同的端口上):一个仅用于 Edge,第二个用于 IE、FF 和 Chrome。这样它似乎工作得相当稳定(在 win-10 和 Selenium-3.4.0 上运行的 Edge build 15063 上测试)
附加信息:
除上述之外,Edge 驱动程序有一些限制,需要在配置中采取特定的解决方法:
尝试将 -D 参数放在 -jar 参数之前。我遇到了一个问题,它认为 -Dwebdriver ..... 是 selenium 本身而不是 java 的参数。