views:

405

answers:

1

I am trying to run a headless test for a web application using WebDriver on Mac OS X 10.6.3. My plan is to run firefox-x11 with Xvfb, but WebDriver is unable to launch firefox-x11. My code is:

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();
}

but this fails with:

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)

When I manually launch /opt/local/bin/firefox-x11-devel-standalone from the terminal, it seems to work fine despite some harmless errors shown. So, I tried to patch the org.openqa.selenium.firefox.FirefoxBinary.copeWithTheStrangenessOfTheMac(ProcessBuilder) method to ignore the errors and exit value of 1. Now it proceeds further, but fails with:

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

Has anyone got WebDriver to work with firefox-x11? This post seems to suggest that one person had got it working, but it does not contain much details.

A: 

It looks like $DISPLAY is not set correctly; it's set by launchd instead of to the display you've configured Xvfb to use.

Nicholas Riley
@Nicholas, I am unable to launch firefox-x11 from WebDriver. My attempt is to get it running with X11 first, and then go to Xvfb. What is the correct way to set `$DISPLAY`?
binil
If you want to do that, set $DISPLAY to something that is not launchd-generated (i.e., :0.0). The auto-X11-server-launching does not play well with headless processes.
Nicholas Riley