Archive for the ‘Uncategorized’ Category.

Selenium-Client 1.2.18 has excellent logging and error messages.

I am impressed with the new logging and stability features of  Selenium-Client 1.2.18. One of the most useful improvements is the automatic failure when a page is showing service unavailable.

I used to put a line like this after every browser.open command.

browser.text?("Http/1.1 Service Unavailable").should(be_false)

Now I get a nice error message from the Selenium-Client.
Selenium::CommandError: Response_Code = 503 Error_Message = Service Unavailable

Test navigation in Rubymine (control +T )

I like to navigate through Rubymine using only keyboard shortcuts if I can. One of the most useful techniques I have found is mapping a keyboard shortcut to enable you to run the test that your cursor is on. This way you can navigate up and down tests using ctl + up or down and then run the test your interested in with your key stroke. Even though I am on a Mac I prefer running a test to be mapped to control + t. The default configuration for this is command + alt + F8. The keymap configuration is under the label Run context configuration, which is under the All Actions -> Other section in the Keymap configuration menu.

Picture 2

The other shortcut that goes well with this one is Go To Test. I can put my cursor on a class name and press alt+shift+t and I can view the tests implementation for this class. Then I can use the short cut I created ctrl + t to run a test I am interested in.

Configure the Team City rake runner to launch Selenium Grid tests.

This article will describe how I was able to use the team city rake runner to launch selenium grid tests.  I learned a few tricks to get this to work correctly.   I first had to learn the makeup of a rspec specktask.  Next I needed to understand how to pass in spec options and lastly I needed to write a rake task that would execute in an exact order.  I needed to still generate the html report with the rake task so I had to add the formatter path to the rake runner

Setup the report formatter path in your rake runner like you do in your rake file.
See the code below to see how the formatter path is setup in the rake file. You can also see how the formatter path is used by the rake task.

# Make sure we pick up the reporter from the appropriate selenium-client
# install as RSpec runner --require does not discriminate between multiple
# selenium-client gems.
report_formatter_path = `gem which -q "selenium/rspec/reporting/selenium_test_report_formatter"`.chomp
report_formatter_path.gsub! /selenium-client-\d+\.\d+.\d+/, "selenium-client-1.2.7"
Spec::Rake::SpecTask.new("spec:run_in_parallel_report") do |t|
  t.spec_files = FileList['./*_spec.rb']
  t.deep_test :number_of_workers => 6,
              :timeout_in_seconds => 300
  t.spec_opts << '--color'
  t.spec_opts << "--require 'rubygems,#{report_formatter_path}'"
  t.spec_opts << "--format=Selenium::RSpec::SeleniumTestReportFormatter:./tmp/test_report.html"
  t.spec_opts << "--format=progress"
  t.fail_on_error = false
end

Setup the spec opts in the rake runner.
See the image below. I need to tell team city which formatter to use and where to put the html report. To pass in spec options to the rake runner in team city just put them in the text field labeled RSpec options(SPEC_OPTS): .
My full spec ops string is:

–require ‘/usr/lib/ruby/gems/1.8/gems/selenium-client-1.2.7/lib/selenium/rspec/reporting/selenium_test_report_formatter.rb’ –format=Selenium::RSpec::SeleniumTestReportFormatter:./tmp/test_report.html
RakeRunner

Run your rake task.
I made a rake task to take selenium grid environment variables as arguments.  If you wanted to run the task above, just add the task name  “spec:run_in_parallel_report” in your rake configuration. You don’t need any command line parameters for the spec:run_in_parallel_report task.

Run selenium ruby scripts in parallel from Team City.

I recently found out why my automated tests run in parallel from my workstation, but then run in sequence from a team city build agent.  It all comes down to the rake runner in team city.  Team city uses a customized rake runner that extends rspec’s spec task.  You get all of the per test reporting, graphing and historical information from team city’s customized rspec reporting.  All this is great if you don’t mind running your tests in sequence, but If your using team city to launch automated web test using the selenium grid this is bad news.

I use a rake file to control the execution of my ruby selenium scripts. I modeled it from the ruby example in the selenium grid distribution. What is important to know about the run in parallel rake task is that it is not your normal rake task. It is first a rspec spec task.  This is a test runner from rspec that allows you to use a rake task to run specs. Not only is it a spec task, it also has been overridden by deep test, the software package that adds parallelization.  Since the spec task is actually deep test’s spec task and not the rspec spec task there are dependencies on what version of rspec deep tests needs.  You must run with rspec 1.1.8 so that the spec task that deep test overrides will work correctly.

So what happens when you run your deep test spec task from team city with their rake runner?   Deep test cannot launch your tests in parallel because Team City is using their customized spec task.  The solution is to use the command line runner to launch your rake task for the selenium grid, then your spec task will have access to the correct rspec gem for deep test to use as a spec runner.

Time to start the blog.

I have been convinced in to starting a technical blog like many of my technology colleagues in Austin.  I will be posting information as I learn from my work experiences so that I can help better the coding community.