When running firebug in firefox via the Selenium webdriver, consider that everytime you run your test, firebug acts like its the first time it’s ever been run(since this is a new browser profile).

I was recently shown a way to disable the first-run tab from appearing.

The Ruby code is below. It also shows how to add firebug and firepath to it as well as setting some custom profile/client rules for firefox


profile = Selenium::WebDriver::Firefox::Profile.new
profile["dom.max_script_run_time"] = 500
profile.log_file = ("C:\\Selenium\\firefox.#{Time.now.strftime("%Y-%m-%d.%H%M%S")}.log")
profile.add_extension("C:\\Selenium\\firebug-1.8.2.xpi")
profile["extensions.firebug.currentVersion"] = "9.99"
profile.add_extension("C:\\Selenium\\firepath.xpi")
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120 # seconds

driver = Selenium::WebDriver.for :firefox, :profile => profile, :http_client=> client

Using CSS selectors in Selenium

So we all know how CSS selectors work but using them to identify elements on a page can be difficult in Selenium, and especially confusing for the beginner Selenium user.

Lets suppose you have a web element that looks like this

<a target=”foo” href=”bar.htm”>SomeWebLink</a>

How would you reference this element?  Well if its the only <a> element on the page, you can definitely call it using by tag.  However, typically it isn’t the only link on the page.

Here are a few ways to call the element by CSS selector:
a
a[href='bar.htm']

Now lets try a harder example:

<a target=”foo” href=”bar_somerandomnumber.htm”>SomeWebLink</a>

Given that the href is constantly changing(lets assume that the random number changes on every page load), you can’t quite specify the href.  However, we can use the beginning and end if we know it.
a[href^=bar][href$=htm]

The ^ tells it to search from the beginning of the attribute and the $ says to search from the end.

To simulate a grid with multiple machines on your local box, you can actually just open multiple command prompts and run seperate instances of the selenium jar in each.

To do this you need to have 1 command prompt running as the hub:


~$ java -jar selenium-server-standalone-2.5.0.jar -role hub

The other command prompts can be added with a specific type of grid instance running in each


~1$ java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5559 -browser browserName=firefox

~2$ java -jar selenium-server-standalone-2.5.0.jar -role webdriver -hub http://localhost:4444/grid/register -port 5556 -browser browserName="internet explorer",platform=WINDOWS

Note the special browsername specification for IE. This comes from the bottom section of the grid specification where they specify special browserNames for different types of browsers

Unfortunately, I was unable to find this specified in any documentation, so I’m putting it here in hopes people will have the same questions I do.

If for some reason you need to run your webdriver tests in DEBUG mode, and don’t want to use the -r flag next to your ruby call (ruby -r testfile.rb….) you can just put $DEBUG=true at the top of your testfile.rb which will also put webdriver into debug mode.

© 2012 Randoms from Blackberry Suffusion theme by Sayontan Sinha