尝试通过Selenium Grid独立jar 3.14在LINUX上创建FIREFOX驱动程序时如何解决SessionNotCreatedException异常

时间:2019-01-15 10:38:07

标签: java selenium selenium-webdriver webdriver selenium-grid

尝试通过Selenium独立jar 3.14创建驱动程序时,我遇到org.openqa.selenium.SessionNotCreatedException异常。

我已经使用以下命令启动集线器和节点

1)java -jar selenium-server-standalone-3.141.59.jar -role hub

2)java -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://192.xxx.xx.xxx:4444/grid/register -port 5556 -browser browserName = chrome,maxInstance = 3 -browser browserName = firefox,maxInstance = 3

尝试通过以下代码创建驱动程序

System.setProperty("webdriver.gecko.driver",
System.getProperty("user.dir") + "/drivers/" +"geckodriver");
DesiredCapabilities caps = DesiredCapabilities.firefox();
caps.setBrowserName("firefox");
caps.setPlatform(Platform.LINUX);
caps.setVersion("64.0");
driver = new RemoteWebDriver(new URL("http://192.xxx.xx.xxx:4444/wd/hub"),caps);

我正在接受以下例外:

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=firefox, moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}, platform=LINUX}], required capabilities = Capabilities [{}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'HP-ProBook-440-G5', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-43-generic', java.version: '1.8.0_181'
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.jio.web.base.TestBase.initDriver(TestBase.java:290)
    at com.jio.web.base.Setup.assignDriver(Setup.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:514)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:215)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:178)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

1 个答案:

答案 0 :(得分:1)

由于您的 Selenium Grid节点正在使用 geckodriver Selenium Grid Hub 进行通信,因此您需要启动 Selenium网格节点,其中 geckodriver 的绝对位置如下:

java -Dwebdriver.gecko.driver=/path/to/geckodriver -jar selenium-server-standalone-3.141.59.jar -role webdriver -hub http://192.xxx.xx.xxx:4444/grid/register -port 5556 -browser browserName=chrome,maxInstance=3 -browser browserName=firefox,maxInstance=3