您好,我一直在使用 Maven 和 TestNG 框架开发一个副项目。到目前为止,我的代码与 WebDriver 实例(Chrome、Firefox、Edge)配合良好,但在尝试使用 Edge 设置 RemoteWebDriver 时不断收到错误。以下是我如何设置我的 Driver 类(实现 WebDriver 类):(显示通过 RemoteWebDriver 初始化 Driver 的构造函数部分:
Edits:
public Driver (String browserName) {
this.browserName = browserName;
....
if(browserName.equalsIgnoreCase("edge")) {
System.setProperty("webdriver.edge.driver","./resources/webdrivers/MicrosoftWebDriver.exe");
DesiredCapabilities browser = DesiredCapabilities.edge();
browser.setPlatform(Platform.WIN10);
try {
this.driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), browser);
} catch (MalformedURLException e) {
e.printStackTrace();
}
js = (JavascriptExecutor) driver;
bugCapture = (TakesScreenshot)driver;
testFailDir = newFailCapDir();
}
当使用 maven 运行代码并设置 -Browser=edge 时,这是我收到的错误:
org.openqa.selenium.remote.UnreachableBrowserException:
Could not start a new session. Possible causes are invalid address of the
remote server or browser start-up failure.
Build info: version: '3.7.1', revision: '8a0099a', time: '2017-11-
06T21:01:39.354Z'
System info: host: 'LAPTOP-L1BFDSGL', ip: '10.0.0.11', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: driver.version: Driver
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to
localhost:17556 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed:
Connection refused: connect
Caused by: java.net.ConnectException: Connection refused: connect
经过一番研究,我认为问题是我没有 Selenium-server-standalone jar 文件,它似乎调用了 Selenium jar 文件的 Maven 依赖项。我已经浏览过这个网站和其他网站,以找到我的问题的解决方案,但我仍然遇到同样的错误。是否有我丢失的文件或者 RemoteWebDriver 可以与 Edge 驱动程序一起应用吗?
在这种情况下任何建议都会有帮助。
谢谢。
更新
@DebanjanB 的请求,我使用的集线器是在声明期间。经过一番研究后,我没有意识到我不需要激活集线器或节点。 (可能是为什么我遇到无法访问的异常。)我还检查了我是否可以设置集线器和节点(我使用端口 -5555 作为节点角色)。我在单独的 cmd 提示符中用于 Hub 和 Node 的命令:
java -jar selenium-server-standalone-3.10.0.jar -role hub
java -jar selenium-server-standalone-3.10.0.jar -role node -hub
http://localhost:4444/grid/register -port 5555
我还更新了我的 Maven 依赖项以包含到独立的 Selenium 服务器。
我为测试运行的 Maven 是:
mvn test -Dbrowser=edge -Dgroups=<specified group>
当我运行集线器时,我收到以下异常错误:
org.openqa.selenium.remote.UnreachableBrowserException:
Could not start a new session. Possible causes are invalid address of the
remote server or browser start-up failure.
Build info: version: '3.10.0', revision: '176b4a9', time: '2018-03-
02T19:03:16.397Z'
System info: host: 'LAPTOP-L1BFDSGL', ip: '10.0.0.11', os.name: 'Windows
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_162'
Driver info: driver.version: Driver
Caused by: java.net.ConnectException: Failed to connect to /10.0.0.11:4444
Caused by: java.net.ConnectException: Connection refused: connect
在失败之前我看到了这样的消息:
2018 年 3 月 9 日下午 7:05:25 org.openqa.selenium.remote.DesiredCapability
边缘
信息:使用new EdgeOptions()
优先于DesiredCapabilities.edge()
//有关测试用例失败并跳过的错误
@DebanjanB 如果您需要更多说明,请告诉我。
更新:
我设法使用 Edge 让我的远程 Webdriver 正常工作。我不得不提到在设置集线器后注册节点时我将要使用的 Dwebdriver。
注册我的节点:
java -Dwebdriver.edge.driver=MicrosoftWebDriver.exe -jar selenium-server-standalone-3.10.0.jar -role 节点 -hubhttp://localhost:4444/grid/register-端口5555
(我还为路径添加了物理驱动程序,因为在本地驱动程序上运行时,我将它们放置在不同的路径中。)
在我的 Driver 类中(我必须将 URL 设置为节点而不是集线器):
System.setProperty("webdriver.edge.driver","./resources/webdrivers/MicrosoftWebDriver.exe");
DesiredCapabilities browser = DesiredCapabilities.edge();
try {
driver = new RemoteWebDriver(new URL("http://10.0.0.19:5555/wd/hub"), browser);
} catch (MalformedURLException e) {
e.printStackTrace();
}
现在,当我运行 Edge 命令时没有问题。 :)