[Home] [Blog] [Contact] - [Talks] [Workshop] [Bio] [Customers]
twitter linkedin youtube github rss

Patrick Debois

Dancing with Selenium, Firefox 3 and Safari on Mac OSX

I must say, Selenium is fun to play with but not really an out of the box experience. At least not the Selenium-RC part.
I've downloaded the "Selenium Remote Control 1.0 beta-1" version to try it out and created a small java app to run it directly from java.
Sample Code:
SeleniumServer server = null;
 DefaultSelenium browser=null;
try {
 	//create a selenium server on port 4444 and enable multiwindow support (=true);
       server=new SeleniumServer(4444,false,true);
	server.start();
        //create a new browser and point it to the selenium server on 4444
	//use firefox in *chrome mode to use the captureEntirePageScreenShot function
	browser=new DefaultSelenium("localhost", 4444, "*chrome", "http://www.jedi.be");
	browser.start();
	browser.windowMaximize();browser.setBrowserLogLevel("debug");
browser.open("http://www.jedi.be");
browser.captureEntirePageScreenshot("/tmp/snapshot.png");
} catch (Exception e) {	e.printStackTrace()	if(server!=null) {
server.stop();
	}
	if(browser!=null) {
browser.stop()
	}
}
Firefox 2.x: mostly OK This worked ok for most of my test URL's my Firefox 2 : Build identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.17) Gecko/2008082910 Firefox/2.0.0.17.For some sites it would print out an error saying:
//5:48:53.018 INFO - Got result: ERROR: Selenium failure.
Please report to the Selenium Users forum at http://forums.openqa.org,
with error details from the log window.
The error message is: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsIDOMCanvasRenderingContext2D.drawWindow] on session
6f08be65c1ec452b851337adda9590bb
It would this on simple pages and would often keep doing this for the next pages as well. The way the screens are captured is that selenium makes use of the canvas element and tries to make a image out of it using the drawWindow command.
I considered that this might be a problem for firefox 2.x so I decided to upgrade to Firefox 3.x
Firefox 3.x: first hangs then fixed I went to download the firefox 3 app and replaced my /Application/Firefox.app with the new version. I re-ran the same code and Firefox 3 would just hang printing a message:
Preparing Firefox profile...
It turns out that the plugins Selenium puts in to the default profile it creates, still contain the maxVersion of 2.x. I followed the procedure on http://www.spacevatican.org/2008/9/27/selenium-and-firefox-3 and updated the install.rdf files within the selenium-server.jar and this would launch my firefox3 happily.
Alas, the same error:
returned failure code: 0x80004005 (NS_ERROR_FAILURE)
[nsIDOMCanvasRenderingContext2D.drawWindow] on session
6f08be65c1ec452b851337adda9590bb
But I still had another browser on my Macbook, on to Safari...
Safari: launch error, popups and crash ... launch error
Quickly change the line *chrome to *safari and the code would crash complaining about:
cp: /Library/Preferences/SystemConfiguration/preferences.plist.old: Permission denied
This file is not present, but Selenium is trying to make a backup of the network preferences using the network-setup command. It seems if this ever fails the preferences file can become corrupt.
I deleted the file, but it would not help, only making another error. Beware: deleting the file looses all your preferences. I ran the network preferences and it was empty. I rebooted and this file was recreated and I could now run the program and have Safari launch itself. But after another crash it would again complain about the permission denied. I again deleted the file but also decided to run.
Another mail suggested to run fix permissions:
# diskutil repairPermissions /
Started verify/repair permissions on disk disk0s2 Macintosh HD
[ | 0%..10%..20%......................................... ]
And this would help, as for now.
popups blocked
Now Safari was launched but the TestRunner would not execute anything. The log window revealed:
error(1224061648997): Couldn't open app window; is the pop-up blocker enabled?
So I opened the Safari and changed the preference to allow pop-ups. And this got me further.
crashes
But then it crashes when Safari tries to make the snapshot saying:
Undefined value on session 7b5337cdfcb842f3a69cdfdf3a8cb591
It showed that maybe because I was test driving URL's outside my initial domain www.jedi.be, this would only be possible with *chrome , *iehta or running in proxy injection mode.
I added
server.setProxyInjectionMode(true);
But it would complain about:
WARN - no transformation seen for key @SESSION_ID@
This seems to be a bug in the 1.0-beta-1 . And there is a fix: I'll stil have to figure this out....