Ruby and selenium for a newbie


I am looking at automation using selenium with the ruby api, and am
having a little problem.

im not sure other than making @selenium into a global variable how can i
use it across multiple files.

so i have three files:


require ‘test’


require “selenium”
require “test/unit”

class Setup1 < Test::Unit::TestCase

def setup
  @verification_errors = []
  if $selenium
    @selenium = $selenium
    @selenium ="localhost", 4444,

“*firefox”, “”, 10000);

def teardown
  @selenium.stop unless $selenium
  assert_equal [], @verification_errors



require “selenium”
require “test/unit”
require ‘setup1’

class Test1 < Test::Unit::TestCase

def test_1"/")
  @selenium.type "q", "selenium rc" "btnG"
  @selenium.wait_for_page_to_load "30000"
  assert @selenium.is_text_present("Results * for selenium rc")


this runs, but stops when it reaches"/").

NoMethodError: private method `open’ called for nil:NilClass

As Test1 is already a subclass of TestCase, I am unable to make it a
subclass of Setup1.

I have read about modules, and amended the code with “include Setup”,
but it appears I have no control over it running the Setup method each
time a new Test is added.

Essentially, I want to know how reference variables across mutiple
files, and as @selenium is an intsance variable, does this mean its only
accessibly by objects which are created from the Setup1 class.

And I get the impression $global variables are a no no, but on the fact
that the @selenium value(browser url) wont change, wouldnt it be ok to
set it as a global?

Please help!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs