views:

324

answers:

1

I'm trying to set the environment for testing using Selenium and selenium-client gem. I prefer unit test style over RSpec style of tests.

Do I have to build my own system for reporting then?

How can I add exception handling without having begin-rescue-end in each test? Is there any way to do that using mixins?

A: 

I'm not sure I understand what your question means in terms of reporting but the selenium-client gem handles both BDD and UnitTesting.

Below is code copied from the rubyforge page:

require "test/unit"
require "rubygems"
gem "selenium-client", ">=1.2.16"
require "selenium/client"

class ExampleTest < Test::Unit::TestCase
    attr_reader :browser

  def setup
    @browser = Selenium::Client::Driver.new \
        :host => "localhost",
        :port => 4444,
        :browser => "*firefox",
        :url => "http://www.google.com",
        :timeout_in_second => 60

    browser.start_new_browser_session
  end

  def teardown
    browser.close_current_browser_session
  end

  def test_page_search
            browser.open "/"
            assert_equal "Google", browser.title
            browser.type "q", "Selenium seleniumhq"
            browser.click "btnG", :wait_for => :page
            assert_equal "Selenium seleniumhq - Google Search", browser.title
            assert_equal "Selenium seleniumhq", browser.field("q")
            assert browser.text?("seleniumhq.org")
            assert browser.element?("link=Cached")
  end

end

As for exception handling, UnitTesting handles the exceptions with an Error message.

That being said, I may have misunderstood your question.

Cuervo's Laugh
Well, as for reporting, I want Selenium-like report (see here: http://labs.fusionlink.com/katapult/images/Image/cfeclipse/pic21.jpg)But, if that is not possible using selenium-client gem, I'd like to create my own, and I would also like to extend it with some things (screenshots of pages that contain errors, for example).In order to do that, I have to catch exceptions. I can do that with "rescue", but that would mean that each of my tests should have begin-rescue-end statement, and that is annoying. Is there another way of doing that?
zorglub76
Could be that you could abstract the begin..rescue with a yield?That way you would only need one abstracted exception block.
Cuervo's Laugh