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.

Comments are closed.