Top Rounds
[Hide Navigation]

Ruby driver for Sahi ·

The Ruby driver for Sahi is available as a gem. http://rubygems.org/gems/sahi

To install:
gem install sahi

This gem is a ruby client for the Sahi proxy. Sahi needs to be installed on your system for this to work. If you are new to Sahi, read http://sahi.co.in/w/using-sahi to get familiar.

Have a look at sahi_test.rb in the sahi/ruby/ folder to see how this driver is used.

Full documentation is available as RDocs

A small example:

require 'test/unit'
require "sahi"

class SahiDriverTest < Test::Unit::TestCase
 def setup
    @browser = init_browser()
    @browser.open
  end

  def teardown
    if @browser
      @browser.close
      sleep(1)
    end

  def init_browser()
   # Look at sahi/userdata/config/browser_types.xml to configure browsers.
    @browser_name = "firefox"
    return Sahi::Browser.new(@browser_name)
  end

  def test_google()
    @browser.navigate_to("http://www.google.com")
    @browser.textbox("q").value = "sahi forums"
    @browser.submit("Google Search").click
    @browser.link("Forums - Sahi - Web Automation and Test Tool").click		
    @browser.link("Login").click
    assert @browser.textbox("req_username").exists?
  end
end

Recording Ruby code

  1. Open sahi/config/sahi.properties and set controller.mode=ruby
  2. Restart Sahi
  3. Open a fresh browser with the proxy configured and navigate to any website.
  4. Press CTRL-ALT and DblClick on the page to bring up the Sahi Java Controller.
  5. Click on the record button and start performing actions on the browser. Steps will be visible in the “Recorded Steps” section.
  6. Copy the code from the Sahi console and paste it into your Ruby script.



---


Top Rounds