【问题标题】:Throws SessionNotCreatedException While running test in Firefox在 Firefox 中运行测试时抛出 SessionNotCreatedException
【发布时间】:2018-01-16 11:59:36
【问题描述】:

我使用的是以下版本:

Selenium: 3.6.0
Mozilla: 56.0
Gecko Driver: V 0.19.0

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

日志: org.openqa.selenium.SessionNotCreatedException:无法创建新的远程会话。所需功能 = 功能 [{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}], 所需功能 = 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) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108) 在 org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224) 在 org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146) 在 org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166) 在 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.runSequentially(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) 在 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) 在 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);
}

【问题讨论】:

  • 粘贴您尝试运行的代码。
  • if(browser.equalsIgnoreCase("firefox")) { DesiredCapabilities 能力 = DesiredCapabilities.firefox();能力.setCapability(“木偶”,真);能力.setCapability(“平台”,Platform.ANY); capabilities.setCapability("binary", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); driver=new FirefoxDriver(capabilities);
  • 始终通过编辑您当前的问题描述并更新它来粘贴您的代码。我建议了一个解决方案,请尝试一下。
  • 是的,当然。我会处理好这个的。

标签: java selenium firefox selenium-webdriver geckodriver


【解决方案1】:

我认为您在初始化 FirefoxDriver() 之前没有更新壁虎驱动程序的路径,所以

  • 第一个:您需要下载 geckodriver 才能运行 Firefox。 Download Link for Gecko Driver
  • 第二个:在启动驱动程序之前,您可能需要设置壁虎驱动程序的路径。

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

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

【讨论】:

  • 我在@BeforeTest 中设置的系统属性
  • 将您的 Firefox 更新到 57,使用 selenium 3.8.1 并使用最新的 gecko 驱动程序。
【解决方案2】:

更新到最新的浏览器版本来解决这个问题。如果坚持使用特定的浏览器版本,geckodriver 和 selenium 框架就会变得不兼容。更新您的 Firefox 版本,可能会出现错误

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2011-04-17
    相关资源
    最近更新 更多