Hi Shinoj,
On Feb 2, 11:33 pm, Shino <
shinoj....@gmail.com> wrote:
> I have 2 doubts while working with selenium RC and Ruby. Could anyone
> please help me.
>
> 1. I recorded some test using selenium IDE
> 2. Exported the test with option "Ruby - Selenium RC".
> 3. Installed Ruby
> 4. Installed selenium client (gem install selenium-client)
> 5. I downloaded and set up Selenium RC in my machine.
> 6. I started selenium server from command prompt (-jar selenium-
> server.jar)
> 7. Now able to run the ruby scripts(rb file).
>
> Question 1: There is no test result/report generated after test run.
> Could anyone let me know how we can generate test result when we work
> with Selenium RC using ruby script ? Will Test Runner work with
> Selenium RC and Ruby combination? If so how?
>
To get started on how to automate report generation with RSpec. You
can look at a the selenium-client examples (
http://github.com/ph7/
selenium-client/tree/6892a388b2dc5ba6e6bd7cc27a901bb76d0b7b4e/
examples) or the ones included in the Selenium Grid distribution
(
http://github.com/ph7/selenium-grid/tree/
009d66b3fb5c1a974c3383938678aa9484214d70/examples/ruby) .
if you are already familiar with rake and RSpec just add in your
rakefile a task like:
require "rubygems"
require "spec"
require "selenium/client"
require "selenium/rspec/spec_helper"
require 'spec/rake/spectask'
desc 'Run acceptance tests for web application'
Spec::Rake::SpecTask.new(:'test:acceptance:web') do |t|
t.libs << "test"
t.pattern = "test/*_spec.rb"
t.spec_opts << '--color'
t.spec_opts << "--require 'rubygems,selenium/rspec/reporting/
selenium_test_report_formatter'"
t.spec_opts << "--
format=Selenium::RSpec::SeleniumTestReportFormatter:./tmp/
acceptance_tests_report.html"
t.spec_opts << "--format=progress"
t.verbose = true
end
You would then get reports like this one:
http://ph7spot.com/examples/selenium_rspec_report.html
If you are still not familiar with Rake and RSpec I recommend you put
in place RSpec default reporting first (
http://rspec.info,
http://www.railsenvy.com/2007/6/11/ruby-on-rails-rake-tutorial).
> Question 2: Is it possible to start selenium server from the ruby file
> which I am running? I mean, when I try to run my script, it should
> automatically start selenium server and at the end of test it should
> stop the server. Is there any way to do this from ruby file?
>
While this is possible I strongly recommend against having the tests
themselves start selenium RC. It is a lot more efficient and flexible
to automate Selenium RC start at the Rakefile level, and then have
your test tasks depend on it. This way you still get the benefit of
"it just works" when running your test suite but developing and
troubleshooting individual tests is a lot quicker and a lot more
efficient: You typically keep a Selenium RC running on your system
while you are editing and running the test.
If you buy that argument the selenium-client gem provides Rake task to
start stop Selenium RC (in the foreground or the background):
require 'rubygems'
require 'selenium-client'
require 'selenium/rake/tasks'
Selenium::Rake::RemoteControlStartTask.new do |rc|
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
rc.background = true
rc.wait_until_up_and_running = true
rc.jar_file = "/path/to/where/selenium-rc-standalone-jar-is-
installed"
rc.additional_args << "-singleWindow"
end
Selenium::Rake::RemoteControlStopTask.new do |rc|
rc.host = "localhost"
rc.port = 4444
rc.timeout_in_seconds = 3 * 60
end
You can get more details about the selenium-client gem at
http://github.com/ph7/selenium-client/tree/master
The Selenium gem also offers similar functionalities (http://
selenium.rubyforge.org/document.html) and also bundles the RC jar.
Good luck,
- Philippe Hanrigou
http://ph7spot.com