我试图让 Selenium 在测试时安装扩展。我正在使用最新的独立 JAR ( selenium-server-standalone-2.26.0.jar
) 和 Firefox 17 来运行我的测试。当我不尝试添加扩展时,该程序运行良好。
我已经多次验证我尝试使用的扩展文件存在并且可以被程序访问,并且实际上包含有效的 install.rdf,因为我使用它在我的默认 Firefox 配置文件中手动安装扩展。
我的代码是:
FirefoxProfile fp=new FirefoxProfile();
File ext=new File("myext-2.17.xpi");
try {
fp.addExtension(ext);
fp.setPreference("extensions.myext.version", "myext-2.17");
} catch (Exception e2) {
e2.printStackTrace();
}
WebDriver wd=new FirefoxDriver(fp);
完整的堆栈跟踪如下:
Exception in thread "pool-1-thread-2" org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(C:\Program Files (x86)\Mozilla Firefox\firefox.exe) on port 7055; process output follows:
null
Build info: version: '2.26.0', revision: '18041', time: '2012-11-01 19:33:38'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_02'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:122)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:243)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:109)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:189)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:178)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)
at TrafficGenerator.BrowserWindow.run(BrowserWindow.java:80)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.openqa.selenium.WebDriverException: org.openqa.selenium.WebDriverException: Cannot locate node containing extension id: C:\Users\Vivek\AppData\Local\Temp\unzip3924903411706376479stream\install.rdf
Build info: version: '2.26.0', revision: '18041', time: '2012-11-01 19:33:38'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_02'
Driver info: driver.version: FirefoxDriver
Build info: version: '2.26.0', revision: '18041', time: '2012-11-01 19:33:38'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_02'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.internal.FileExtension.readIdFromInstallRdf(FileExtension.java:141)
at org.openqa.selenium.firefox.internal.FileExtension.writeTo(FileExtension.java:60)
at org.openqa.selenium.firefox.FirefoxProfile.installExtensions(FirefoxProfile.java:465)
at org.openqa.selenium.firefox.FirefoxProfile.layoutOnDisk(FirefoxProfile.java:443)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:77)
... 10 more
使用FF16和FF9也存在错误。关于可能导致错误的原因以及如何修复它的任何想法?