Archive for the ‘Ruby’ Category.

Essentials of getting started with Selenium Grid and Ruby.

I have been running test/unit scripts on the grid for a while now and I was trying to remember where I got my test/unit syntax from.  I was looking to create a live template to create new test scripts in Rubymine. You actually have to make sure that you create the Selenium Driver object in a specific way or your scripts will not run on the Selenium Grid or they will not run in parallel correctly.  Your test class must also always have a setup and tear down, even if you call a method out side of the class to setup the driver.

There are 2 sources of information that you must understand and monitor for updates.  First is the Selenium Grid home page.  Recently when Firefox 3.5 became available, I needed to update the version of the grid software I was using.  The other site is the site for the selenium client gem. You can find documentation here on how to structure your spec and test/unit scripts so that they run on the grid.  The gem and the grid  are both maintained by the same person.  I revisit the sites often to pick up tips on how to structure rake files and get tips for running scripts in parallel. In working with this software, I have become very familiar with the files in the rspec, deeptest, and selenium-client gems.

Using the selenium IDE and Rubymine

This post explains how to debug a Selenium test script in Rubymine like you would in the selenium IDE. It is common to have a missing element failure in a recorded selenium script.  A quick way to debug this in the Selnium IDE is to put a break point in your script and use the execute command button to find the right code for your failing command.
Add breakpoints start and stop test execution

Add breakpoints start and stop test execution

In the case of a failing script you can see below that the failing line is highlighted in red and you can see the log message explaining the error.
Failing script

Failing script

So when you export your selenium IDE script to your favorite language, how do you trouble shoot failures like this easily in your development environment?
Test Script

Test Script

I generated an error in the script by changing the name of the google button from “btnG” to “btn” .  Trouble shoot this error by using the Rubymine debugger and evaluate expression tool.  I put a break point on the line of code that is failing.  Then I can select the text and open the evaluate expression tool to see if I can locate the button.
picture-15

When you get the expression correct, you will see a message, result = nil.  This is a great tool for testing xpath expressions.

Successful Evaluation

Successful Evaluation

If you noticed that the code I used in this example is different than what is exported from the Selenium IDE, it is because I use the selenium-client gem and execute my tests using the selenium grid.