我正在尝试在 Mac OS X 10.6.3 上使用 WebDriver 对 Web 应用程序运行无头测试。我的计划是用 Xvfb 运行 firefox-x11,但是 WebDriver 无法启动 firefox-x11。我的代码是:
System.setProperty("webdriver.firefox.bin",
"/opt/local/bin/firefox-x11-devel-standalone");
WebDriver browser = new FirefoxDriver();
try {
browser.get("http://google.com");
} finally {
browser.close();
}
但这失败了:
org.openqa.selenium.WebDriverException: Unable to start firefox cleanly.
Exit value: 1
Ran from: [/opt/local/bin/firefox-x11-devel-standalone, --verbose, -silent]
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.6.3', java.version: '1.6.0_17'
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.FirefoxBinary.copeWithTheStrangenessOfTheMac(FirefoxBinary.java:200)
at org.openqa.selenium.firefox.FirefoxBinary.startProfile(FirefoxBinary.java:83)
at org.openqa.selenium.firefox.FirefoxBinary.clean(FirefoxBinary.java:264)
at org.openqa.selenium.firefox.FirefoxLauncher.startProfile(FirefoxLauncher.java:66)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.<init>(NewProfileExtensionConnection.java:45)
at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:44)
当我从终端手动启动时,尽管显示了一些无害的错误/opt/local/bin/firefox-x11-devel-standalone
,但它似乎工作正常。因此,我尝试修补该方法以忽略错误并退出值 1。现在它继续进行,但失败并显示:org.openqa.selenium.firefox.FirefoxBinary.copeWithTheStrangenessOfTheMac(ProcessBuilder)
Caused by: org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/opt/local/bin/firefox-x11-devel-standalone) on port 7055; process output follows:
Xlib: extension "RANDR" missing on display "/tmp/launch-tElCRZ/org.x:0".
Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!
(firefox-bin:88837): Gtk-CRITICAL **: gtk_widget_has_screen: assertion `GTK_IS_WIDGET (widget)' failed
ˇXlib: extension "RANDR" missing on display "/tmp/launch-tElCRZ/org.x:0".
Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!
(firefox-bin:88877): Gtk-CRITICAL **: gtk_widget_has_screen: assertion `GTK_IS_WIDGET (widget)' failed
ˇ
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.6.3', java.version: '1.6.0_17'
Driver info: driver.version: firefox
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.connectToBrowser(NewProfileExtensionConnection.java:60)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.<init>(NewProfileExtensionConnection.java:49)
at org.openqa.selenium.firefox.internal.ExtensionConnectionFactory.connectTo(ExtensionConnectionFactory.java:44)
... 4 more
Caused by: org.openqa.selenium.firefox.NotConnectedException: Failed to start up socket within 45000
at org.openqa.selenium.firefox.internal.AbstractExtensionConnection.connectToBrowser(AbstractExtensionConnection.java:143)
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.connectToBrowser(NewProfileExtensionConnection.java:58)
... 6 more
有没有人让 WebDriver 与 firefox-x11 一起工作?这篇文章似乎暗示一个人已经让它工作了,但它没有包含太多细节。