Selenium Grid无法创建新的会话错误

时间:2017-04-03 10:26:31

标签: selenium-grid

我正在学习Selenium Grid和初学者。我使用命令设置我的 hub : -   java -jar selenium-server-standalone-3.3.0.jar -role hub 并使用以下命令设置节点: - java -jar selenium-server-standalone-3.3.0.jar -role webdriver -hub IP_of_hub:4444 / grid / register -port 1234

比我创建了一个java项目并创建了一个类并编写了代码

import junit.framework.Assert;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.xerces.util.URI.MalformedURIException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

    public class selGrid {

        WebDriver driver;
        String base_url,node_url;

        @BeforeTest
        public void setUp() throws MalformedURLException{
            System.setProperty("webdriver.gecko.driver","C://Users//Administrator//Downloads//geckodriver.exe");
            base_url="http://newtours.demoaut.com";
            node_url="http://localhost:1234/wd/hub";
            DesiredCapabilities capability=DesiredCapabilities.firefox();
            capability.setBrowserName("firefox");
            capability.setPlatform(Platform.WINDOWS);

            driver=new RemoteWebDriver(new URL(node_url),capability);
        }
        @AfterTest
        public void afterTest()
        {
            driver.quit();
        }
         public void simpleTest()
        {
            driver.get(base_url);
            Assert.assertEquals("Welcome", driver.getTitle());
        }


      }}

运行它就像下面文本中的TestNGand显示

一样
FAILED CONFIGURATION: @BeforeTest setUp  org.openqa.selenium.SessionNotCreatedException: Unable to create new remote   session. desired capabilities = Capabilities [{marionette=true,    browserName=firefox, moz:firefoxOptions=  {binary=Optional[FirefoxBinary(C:\Program Files (x86)\Mozilla   Firefox\firefox.exe)], args=[], legacy=null, logLevel=null, prefs={},   profile=null}, version=, platform=WINDOWS}], required capabilities =   Capabilities [{}]
  Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
  System info: host: 'UNO-13-PC', ip: '192.168.0.4', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
  Driver info: driver.version: FirefoxDriver
 Command duration or timeout: 0 milliseconds
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:363)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:113)
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 selGrid.setUp(selGrid.java:28)
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:108)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
at org.testng.TestRunner.beforeRun(TestRunner.java:626)
at org.testng.TestRunner.run(TestRunner.java:594)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
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:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
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)
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create   new remote session. desired capabilities = Capabilities [{marionette=true,  browserName=firefox, moz:firefoxOptions= {binary=Optional[FirefoxBinary(C:\Program Files (x86)\Mozilla  Firefox\firefox.exe)], args=[], legacy=null, logLevel=null, prefs={},  profile=null}, version=, platform=WINDOWS}], required capabilities =  Capabilities [{}]
   Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
        System info: host: 'UNO-13-PC', ip: '192.168.0.4', os.name: 'Windows 7',   os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
    Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07   11:21:31 -0800'
System info: host: 'UNO-13-PC', ip: '192.168.0.4', os.name: 'Windows 7',   os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_121'
          Driver info: driver.version: FirefoxDriver
       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.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    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.firefox.FirefoxDriver.<init>(FirefoxDriver.java:243)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:164)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:81)
at org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:63)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:209)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

 SKIPPED CONFIGURATION: @AfterTest afterTest

 ===============================================
 Default test
 Tests run: 0, Failures: 0, Skips: 0
 Configuration Failures: 1, Skips: 1
 ===============================================


 ===============================================
 Default suite
 Total tests run: 0, Failures: 0, Skips: 0
 Configuration Failures: 1, Skips: 1
 ===============================================

1 个答案:

答案 0 :(得分:1)

设置geckodriver的路径并使用最新版本的firefox(或者可以检查兼容的firefox是否为独立服务器)。 现在我使用的是firefox ver 52.0.2,而独立服务器是3.3.0