使用 selenium 网格和 Webdriver 管理器后的功能错误
Capabilities error after using selenium grid and Webdriver manager
我一直在使用 [webdriver manager][1] 进行本地执行,它一直很出色,但是现在我正在尝试使用 selenium 网格,我想使用相同的方法,但我收到一些与功能相关的错误。
集线器和节点是本地主机,这些是我实现的细节:
我用这条线启动集线器:
start cmd /k java -jar selenium-server-standalone-3.5.0.jar -role hub -port 4443
我用这一行启动节点
start cmd /k java -jar selenium-server-standalone-3.5.0.jar -port 5556 -role node -hub http://localhost:4443/grid/register
这是我为浏览器使用的配置,问题出在 chrome,我还没有测试其他的。
public WebDriver cbt(String browser, String methodName) throws Exception{
WebDriver driver;
DesiredCapabilities caps;
//Check if parameter passed from TestNG is 'firefox'
if(browser.equalsIgnoreCase("firefox"))
{
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "Windows 10");
caps.setCapability("version", "53.0");
caps.setCapability("name", methodName);
}
//Check if parameter passed as 'chrome'
else if(browser.equalsIgnoreCase("chrome"))
{
caps = DesiredCapabilities.chrome();
}
else if(browser.equalsIgnoreCase("ie")){
caps = DesiredCapabilities.edge();
caps.setCapability("platform", "Windows 10");
caps.setCapability("version", "14.14393");
caps.setCapability("name", methodName);
}
else{
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
String hub = "http://localhost:4443/wd/hub";
driver = new RemoteWebDriver(new URL(hub), caps);
return driver;
}
这些是我遇到的错误
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'NEYMAR', ip: '169.254.112.118', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
at com.gnow.gnow.Utils.CommonConfiguration.cbt(CommonConfiguration.java:213)
at com.gnow.gnow.Test.Test.setUp(Test.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:590)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
提前致谢
[1]: https://github.com/bonigarcia/webdrivermanager
我首先建议您将 selenium 版本升级到 Selenium 3.5.1
Selenium 3.3.1 中有一个错误,其中实际错误不会传递给最终用户,并且您的堆栈跟踪似乎表明这可能是由于该错误导致您无法看到真正的问题。此错误已在 3.4.0
中修复
在客户端升级到 Selenium 3.5.1 后,您应该会立即看到问题。
既然你提到了 Chrome
,我猜测这可能是因为你的 chromedriver 在 PATH
.
中不可用。
您可能想看看 this tutorial I wrote up on Grid, which tells you the set of things that is required to get the Grid up and running. I have included a lot of other information about the Grid as well in there。
我一直在使用 [webdriver manager][1] 进行本地执行,它一直很出色,但是现在我正在尝试使用 selenium 网格,我想使用相同的方法,但我收到一些与功能相关的错误。
集线器和节点是本地主机,这些是我实现的细节:
我用这条线启动集线器:
start cmd /k java -jar selenium-server-standalone-3.5.0.jar -role hub -port 4443
我用这一行启动节点
start cmd /k java -jar selenium-server-standalone-3.5.0.jar -port 5556 -role node -hub http://localhost:4443/grid/register
这是我为浏览器使用的配置,问题出在 chrome,我还没有测试其他的。
public WebDriver cbt(String browser, String methodName) throws Exception{
WebDriver driver;
DesiredCapabilities caps;
//Check if parameter passed from TestNG is 'firefox'
if(browser.equalsIgnoreCase("firefox"))
{
caps = DesiredCapabilities.firefox();
caps.setCapability("platform", "Windows 10");
caps.setCapability("version", "53.0");
caps.setCapability("name", methodName);
}
//Check if parameter passed as 'chrome'
else if(browser.equalsIgnoreCase("chrome"))
{
caps = DesiredCapabilities.chrome();
}
else if(browser.equalsIgnoreCase("ie")){
caps = DesiredCapabilities.edge();
caps.setCapability("platform", "Windows 10");
caps.setCapability("version", "14.14393");
caps.setCapability("name", methodName);
}
else{
//If no browser passed throw exception
throw new Exception("Browser is not correct");
}
String hub = "http://localhost:4443/wd/hub";
driver = new RemoteWebDriver(new URL(hub), caps);
return driver;
}
这些是我遇到的错误
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'NEYMAR', ip: '169.254.112.118', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
at com.gnow.gnow.Utils.CommonConfiguration.cbt(CommonConfiguration.java:213)
at com.gnow.gnow.Test.Test.setUp(Test.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:590)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
提前致谢
[1]: https://github.com/bonigarcia/webdrivermanager
我首先建议您将 selenium 版本升级到 Selenium 3.5.1
Selenium 3.3.1 中有一个错误,其中实际错误不会传递给最终用户,并且您的堆栈跟踪似乎表明这可能是由于该错误导致您无法看到真正的问题。此错误已在 3.4.0
中修复在客户端升级到 Selenium 3.5.1 后,您应该会立即看到问题。
既然你提到了 Chrome
,我猜测这可能是因为你的 chromedriver 在 PATH
.
您可能想看看 this tutorial I wrote up on Grid, which tells you the set of things that is required to get the Grid up and running. I have included a lot of other information about the Grid as well in there。