此文主要讲述 Java 运行 Selenium 脚本时,因 Friefox 浏览器版本与 selenium-server-standalone-x.xx.x.jar 不兼容引起的 org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary 报错解决方法。
希望能对初学 Selenium2 WebUI 自动化测试编程的亲们有所帮助。若有不足之处,敬请大神指正,不胜感激!
之前给朋友初步介绍了 Selenium 启动不同浏览器的脚本编写,对应源码亲们可参阅博文:WebUI自动化实战实例-003-三种浏览器(Chrome、Firefox、IE)启动脚本。今天,在朋友 PC 上运行时,提示如下的错误信息:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
thod startup on commonfix@mozillaonline.com version 0.9
1421571095765 addons.xpi DEBUG Registering manifest for C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions\wx-assistant@mozillaonline.com.xpi
1421571095765 addons.xpi DEBUG Loading bootstrap scope from C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions\wx-assistant@mozillaonline.com.xpi
1421571095767 addons.xpi DEBUG Calling bootstrap method startup on wx-assistant@mozillaonline.com version 1.1.2
1421571095785 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1421571095785 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1421571095786 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1421571095786 addons.manager DEBUG Registering shutdown blocker for PluginProvider
JavaScript error: file:///C:/Users/机器名/AppData/Local/Temp/anonymous2976645405089665816webdriver-profile/extensions/cpmanager@mozillaonline.com/components/mozCNGuard.js, line 287: TypeError: w.gBrowser is undefined
JavaScript warning: resource://addoninstaller/log4moz.js, line 494: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1421571096533 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1421571096773 addons.xpi-utils DEBUG Starting async load of XPI database C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions.json
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1421571097073 addons.xpi-utils DEBUG Async JSON file read took 0 MS
1421571097073 addons.xpi-utils DEBUG Finished async read of XPI database, parsing...
1421571097074 addons.xpi-utils DEBUG Successfully read XPI database
console.error: commonfix:
Message: TypeError: redeclaration of variable settings
Stack:
@resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 *************************
A coding exception was thrown in a Promise resolution callback.
See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise Full message: TypeError: redeclaration of variable settings
Full stack: @resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 *************************
console.error: commonfix:
Message: TypeError: redeclaration of variable settings
Stack:
@resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 1421571097193 addons.repository DEBUG No addons.json found.
1421571097194 DeferredSave.addons.json DEBUG Save changes
1421571097195 DeferredSave.addons.json DEBUG Starting timer
1421571097250 DeferredSave.addons.json DEBUG Starting write
1421571097253 DeferredSave.addons.json DEBUG Write succeeded at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at main.java.aaron.sele.demo.StartBrowerFirefox.FirefoxStart(StartBrowerFirefox.java:39)
at main.java.aaron.sele.demo.StartBrowerFirefox.main(StartBrowerFirefox.java:54)
Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
thod startup on commonfix@mozillaonline.com version 0.9
1421571095765 addons.xpi DEBUG Registering manifest for C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions\wx-assistant@mozillaonline.com.xpi
1421571095765 addons.xpi DEBUG Loading bootstrap scope from C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions\wx-assistant@mozillaonline.com.xpi
1421571095767 addons.xpi DEBUG Calling bootstrap method startup on wx-assistant@mozillaonline.com version 1.1.2
1421571095785 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1421571095785 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1421571095786 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1421571095786 addons.manager DEBUG Registering shutdown blocker for PluginProvider
JavaScript error: file:///C:/Users/机器名/AppData/Local/Temp/anonymous2976645405089665816webdriver-profile/extensions/cpmanager@mozillaonline.com/components/mozCNGuard.js, line 287: TypeError: w.gBrowser is undefined
JavaScript warning: resource://addoninstaller/log4moz.js, line 494: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1421571096533 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1421571096773 addons.xpi-utils DEBUG Starting async load of XPI database C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions.json
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1421571097073 addons.xpi-utils DEBUG Async JSON file read took 0 MS
1421571097073 addons.xpi-utils DEBUG Finished async read of XPI database, parsing...
1421571097074 addons.xpi-utils DEBUG Successfully read XPI database
console.error: commonfix:
Message: TypeError: redeclaration of variable settings
Stack:
@resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 *************************
A coding exception was thrown in a Promise resolution callback.
See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise Full message: TypeError: redeclaration of variable settings
Full stack: @resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 *************************
console.error: commonfix:
Message: TypeError: redeclaration of variable settings
Stack:
@resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 1421571097193 addons.repository DEBUG No addons.json found.
1421571097194 DeferredSave.addons.json DEBUG Save changes
1421571097195 DeferredSave.addons.json DEBUG Starting timer
1421571097250 DeferredSave.addons.json DEBUG Starting write
1421571097253 DeferredSave.addons.json DEBUG Write succeeded Build info: version: '2.42.2', revision: '6a6995d', time: '2014-06-03 17:42:03'
System info: host: '机器名-PC', ip: '10.24.68.138', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:130)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at main.java.aaron.sele.demo.StartBrowerFirefox.FirefoxStart(StartBrowerFirefox.java:39)
at main.java.aaron.sele.demo.StartBrowerFirefox.main(StartBrowerFirefox.java:54)
Caused by: org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
thod startup on commonfix@mozillaonline.com version 0.9
1421571095765 addons.xpi DEBUG Registering manifest for C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions\wx-assistant@mozillaonline.com.xpi
1421571095765 addons.xpi DEBUG Loading bootstrap scope from C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions\wx-assistant@mozillaonline.com.xpi
1421571095767 addons.xpi DEBUG Calling bootstrap method startup on wx-assistant@mozillaonline.com version 1.1.2
1421571095785 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1421571095785 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1421571095786 addons.manager DEBUG Registering shutdown blocker for OpenH264Provider
1421571095786 addons.manager DEBUG Registering shutdown blocker for PluginProvider
JavaScript error: file:///C:/Users/机器名/AppData/Local/Temp/anonymous2976645405089665816webdriver-profile/extensions/cpmanager@mozillaonline.com/components/mozCNGuard.js, line 287: TypeError: w.gBrowser is undefined
JavaScript warning: resource://addoninstaller/log4moz.js, line 494: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
1421571096533 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1421571096773 addons.xpi-utils DEBUG Starting async load of XPI database C:\Users\机器名\AppData\Local\Temp\anonymous2976645405089665816webdriver-profile\extensions.json
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1421571097073 addons.xpi-utils DEBUG Async JSON file read took 0 MS
1421571097073 addons.xpi-utils DEBUG Finished async read of XPI database, parsing...
1421571097074 addons.xpi-utils DEBUG Successfully read XPI database
console.error: commonfix:
Message: TypeError: redeclaration of variable settings
Stack:
@resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 *************************
A coding exception was thrown in a Promise resolution callback.
See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise Full message: TypeError: redeclaration of variable settings
Full stack: @resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 *************************
console.error: commonfix:
Message: TypeError: redeclaration of variable settings
Stack:
@resource://commonfix-at-mozillaonline-dot-com/commonfix/lib/main.js:231:undefined
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:145:19
startup/</<@resource://gre/modules/commonjs/sdk/addon/runner.js:86:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:865:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:744:7 1421571097193 addons.repository DEBUG No addons.json found.
1421571097194 DeferredSave.addons.json DEBUG Save changes
1421571097195 DeferredSave.addons.json DEBUG Starting timer
1421571097250 DeferredSave.addons.json DEBUG Starting write
1421571097253 DeferredSave.addons.json DEBUG Write succeeded at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)
... 8 more
从信息中可看出,Selenium 无法启动 Friefox 浏览器而导致程序报错信息。解决步骤:
- 初始以为是因为 WebDriver 驱动的问题,更换后发现问题依然存在
- 查看其 Firefox 的版本为 35,觉得问题出在了 Firefox 版本与 selenium-server-standalone 版本不对应导致的,于是将 Firefox 版本降至 31,脚本运行通过;
- 将 Firefox 版本升级为 35,下载最新的 selenium-server-standalone-2.44.0.jar(下载地址:http://yunpan.cn/cyaZTHGtiav9Y 提取码 96a6) 导入工程,脚本运行通过
至此,WebUI 自动化功能测试脚本第 004 篇-解决 Firefox 版本不兼容:org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary 顺利完结,希望此文能够给初学 Selenium 的您一份参考。
最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^