Wednesday, November 17, 2010

Quick Tip: Demoing Selenium with Firefox on OSX

innovation.jpg

Whenever I prepare a presentation that contains a demo with Selenium for web automation, I am fighting with the same stumbling blocks again and again.


Also see my post Quick Tip: Running Selenium on OS X Snow Leopard.

Another thing is the offline-mode of Firefox: If you don't have internet connection during your presentation, selenium-server will start firefox, but firefox will drop into offline mode from which selenium cannot run its browser automation.

Here is a way around this:

1. Create a Firefox profile which will then be used by selenium:
  • Start Firefox with the profile manager: /Applications/Firefox.app/Contents/MacOS/firefox-bin -ProfileManager -no-remote
  • In the profile manager: Create a new profile. I called it 'selenium'. Remember the path to this profile directory that is displayed in the wizard. In my case the path is: /Users/jbandi/Library/Application\ Support/Firefox/Profiles/qd79pvsv.selenium
  • Then start the selenium server with the new profile:
    java -jar selenium-server.jar -firefoxProfileTemplate /Users/jbandi/Library/Application\ Support/Firefox/Profiles/qd79pvsv.selenium


  • 2. Configure the profile to not use offline mode:
  • Start Firefox with the selenium profile (i.e. by running selenium without internet connection).
  • Enter about:config in the location bar.
  • Create (right click) a new boolean preference network.manage-offline-status with the value false.


  • This worked for me with Firefox 3.6.12, Selenium 1.0.3 on OSX 10.6.5.
    There is a lot of info on the net about setting the preference toolkig.networkmanager.disable' to false. This did not work, I think this is only valid on Linux. Also the extension 'StayInOnlineMode' did not solve the problem.


    A trick for better demos with selenium is executing these commands on startup (in my case from java):
    selenium.getEval("window.moveTo(140, 25);");
    selenium.getEval("window.resizeTo(1000, 600);");
    selenium.setSpeed("1000");

    This places and resizes the automated browser window and slows down the automation, so that the audience can actually see what is going on.

    However I did not manage to bring the browser window automatically to the front, it always starts in the background and I have to bring it to front manually (any tip would be appreciated).

    No comments:

    Post a Comment

    Related Posts Plugin for WordPress, Blogger...