引发SessionNotCreatedException在Firefox

时间:2018-01-16 11:59:37

标签: java selenium firefox selenium-webdriver geckodriver

我正在使用以下版本:

Selenium: 3.6.0
Mozilla: 56.0
Gecko Driver: V 0.19.0

当我为mozilla firefox运行testng.xml文件时,它会抛出此异常:

  

日志:   org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。 desired capabilities = Capabilities [{marionette = true,binary = C:\ Program Files(x86)\ Mozilla Firefox \ firefox.exe,browserName = firefox,moz:firefoxOptions = {binary = Optional [FirefoxBinary(C:\ Program Files \ Mozilla) Firefox \ firefox.exe)],args = [],legacy = null,logLevel = null,prefs = {},profile = null},version =,platform = ANY}],required capabilities = Capabilities [{}]   构建信息:版本:'未知',修订版:'b526bd5',时间:'2017-03-07 11:11:07 -0800'   系统信息:主机:'LAPTOP-HS6HUVRH',ip:'9.124.94.212',os.name:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8 .0_151'   驱动程序信息:driver.version:FirefoxDriver       在org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)       在org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)       在org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)       在org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)       在org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)       在org.openqa.selenium.remote.RemoteWebDriver。(RemoteWebDriver.java:131)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:243)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:121)       在org.openqa.selenium.firefox.FirefoxDriver。(FirefoxDriver.java:164)       在com.drlive.base.BaseTest.initApplication(BaseTest.java:126)       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:108)       at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)       在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)       在org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)       at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)       at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)       在org.testng.TestRunner.privateRun(TestRunner.java:744)       在org.testng.TestRunner.run(TestRunner.java:602)       在org.testng.SuiteRunner.runTest(SuiteRunner.java:380)       在org.testng.SuiteRunner.run顺序(SuiteRunner.java:375)       在org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)       在org.testng.SuiteRunner.run(SuiteRunner.java:289)       在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)       在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)       at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)       在org.testng.TestNG.runSuitesLocally(TestNG.java:1226)       在org.testng.TestNG.runSuites(TestNG.java:1144)       在org.testng.TestNG.run(TestNG.java:1115)       at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)       在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)       在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

代码:

if(browser.equalsIgnoreCase("firefox")) { 
DesiredCapabilities capabilities = DesiredCapabilities.firefox(); 
capabilities.setCapability("marionette", true);
capabilities.setCapability("platform", Platform.ANY);
capabilities.setCapability("binary", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); 
driver=new FirefoxDriver(capabilities);
}

2 个答案:

答案 0 :(得分:0)

我认为在初始化FirefoxDriver()之前你还没有更新gecko驱动程序的路径

  • 1st:您需要下载geckodriver才能运行Firefox。 Download Link for Gecko Driver
  • 第二名:您可以在启动驱动程序之前设置geckodriver的路径。

所以你的代码看起来应该是这样的。

System.setProperty("webdriver.gecko.driver", "c:/path_to_driver/geckodriver.exe");
driver = new FirefoxDriver();

答案 1 :(得分:0)

更新为最新的浏览器版本以解决此问题。如果长期使用特定的浏览器版本,则geckodriver和selenium框架将不兼容。更新您的firefox版本,错误可能