在Selenium中失败的testSetup

时间:2016-07-26 11:36:18

标签: java selenium selenium-webdriver

在Jenkins运行的自动化系统中,测试设置有时会失败。当测试设置失败时,它将跳过诉讼中的所有其他测试设置和测试。它在Mozilla Firefox上运行。

有没有机会摆脱异常?

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7056 after 45000 ms. Firefox console output:
1469480338859   addons.manager  DEBUG   Application has been upgraded
1469480338873   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]
1469480338875   addons.manager  DEBUG   Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]
1469480338879   addons.xpi  DEBUG   startup
1469480338880   addons.xpi  DEBUG   Skipping unavailable install location app-system-local
1469480338881   addons.xpi  DEBUG   Skipping unavailable install location app-system-share
1469480338882   addons.xpi  INFO    Mapping {972ce4c6-7e08-4474-a285-3208198ce6fd} to C:\Program Files (x86)\Mozilla Firefox\browser\extensions\{972ce4c6-7e08-4474-a285-3208198ce6fd}
1469480338883   addons.xpi  INFO    Mapping fxdriver@googlecode.com to C:\Users\user\AppData\Local\Temp\anonymous7098252712982546494webdriver-profile\extensions\fxdriver@googlecode.com
1469480338883   addons.xpi  INFO    Mapping JSErrorCollector@jsourcerer.com to C:\Users\user\AppData\Local\Temp\anonymous7098252712982546494webdriver-profile\extensions\JSErrorCollector@jsourcerer.com
1469480338884   addons.xpi  DEBUG   Ignoring file entry whose name is not a valid add-on ID: C:\Users\user\AppData\Local\Temp\anonymous7098252712982546494webdriver-profile\extensions\webdriver-staging
1469480338884   addons.xpi  DEBUG   checkForChanges
1469480338894   addons.xpi  DEBUG   Directory state JSON differs: cache [] state [{"name":"app-global","addons":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"descriptor":"C:\\Program Files (x86)\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}","mtime":1434617609039,"rdfTime":1417010916000}}},{"name":"app-profile","addons":{"fxdriver@googlecode.com":{"descriptor":"C:\\Users\\user\\AppData\\Local\\Temp\\anonymous7098252712982546494webdriver-profile\\extensions\\fxdriver@googlecode.com","mtime":1469480305220,"rdfTime":1469480305217},"JSErrorCollector@jsourcerer.com":{"descriptor":"C:\\Users\\user\\AppData\\Local\\Temp\\anonymous7098252712982546494webdriver-profile\\extensions\\JSErrorCollector@jsourcerer.com","mtime":1469480303712,"rdfTime":1469480303712}}}]
1469480338900   addons.xpi-utils    DEBUG   Opening XPI database C:\Users\user\AppData\Local\Temp\anonymous7098252712982546494webdriver-profile\extensions.json
1469480338901   addons.xpi  DEBUG   New add-on fxdriver@googlecode.com installed in app-profile
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1469480339870   addons.xpi-utils    DEBUG   Make addon app-profile:fxdriver@googlecode.com visible
1469480339874   DeferredSave.extensions.json    DEBUG   Save changes
1469480339878   DeferredSave.extensions.json    DEBUG   Save changes
1469480339878   addons.xpi  DEBUG   New add-on JSErrorCollector@jsourcerer.com installed in app-profile
1469480339886   addons.xpi-utils    DEBUG   Make addon app-profile:JSErrorCollector@jsourcerer.com visible
1469480339887   DeferredSave.extensions.json    DEBUG   Save changes
1469480339887   DeferredSave.extensions.json    DEBUG   Save changes
1469480339887   addons.xpi  DEBUG   New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
1469480339892   addons.xpi-utils    DEBUG   Make addon app-global:{972ce4c6-7e08-4474-a285-3208198ce6fd} visible
1469480339893   DeferredSave.extensions.json    DEBUG   Save changes
1469480339893   DeferredSave.extensions.json    DEBUG   Save changes
1469480339907   addons.xpi  DEBUG   Updating database with changes to installed add-ons
1469480339907   addons.xpi-utils    DEBUG   Updating add-on states
1469480339908   addons.xpi-utils    DEBUG   Writing add-ons list
1469480339919   addons.manager  DEBUG   Registering shutdown blocker for XPIProvider
1469480339921   addons.manager  DEBUG   Registering shutdown blocker for LightweightThemeManager
1469480339924   addons.manager  DEBUG   Registering shutdown blocker for OpenH264Provider
1469480339925   addons.manager  DEBUG   Registering shutdown blocker for PluginProvider
1469480349163   DeferredSave.extensions.json    DEBUG   Starting timer
1469480349708   DeferredSave.extensions.json    DEBUG   Starting write

    at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
    at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:216)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:211)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:124)
    at com.intuit.ifs.csscat.core.WebDriverFactory.getWebDriver(WebDriverFactory.java:104)
    at com.intuit.ifs.csscat.core.BaseTestNGWebDriver.testSetup(BaseTestNGWebDriver.java:71)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:551)
    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:640)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:768)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1113)
    at org.testng.TestNG.run(TestNG.java:1025)
    at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:122)
    at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
    at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:101)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)

Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe)

1 个答案:

答案 0 :(得分:0)

当它无法启动请求的Web驱动程序时会发生这种情况。有两个实例,我个人认为这种情况发生:(1)当Selenium版本和Firefox版本之间存在不兼容性时,(2)当Firefox运行的实例太多且二进制文件无法启动时。既然你说这是间歇性的,我假设(1)不是问题而且会假设你遇到了(2)。我不知道你是否正在并行运行测试,并且不知道自动化的设置我会说简单的解决方案是将WebDriver的创建包装在一个循环中-catch块来处理该异常。我建议使循环无限(例如,给它一个超时)。另请注意,这是一个简单的解决方案,但不一定是最好的解决方案。通常,如何最好地处理资源管理高度依赖于测试环境,运行的测试数量,并行性(如果有的话)等。

另外,请注意,如果您在配置方法(例如设置)中有异常,那么使用TestNG将会跳过其他测试,因为它会在错误的配置上快速失败并且#34;运行测试的心态。如果您希望在捕获和处理这些配置方法中的所有异常时需要保持一致。