Hi
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:
start.rb
···
--------
require 'test'
setup.rb
--------
require "selenium"
require "test/unit"
class Setup1 < Test::Unit::TestCase
def setup
@verification_errors = []
if $selenium
@selenium = $selenium
else
@selenium = Selenium::SeleniumDriver.new("localhost", 4444,
"*firefox", "http://www.google.com/", 10000);
@selenium.start
end
end
def teardown
@selenium.stop unless $selenium
assert_equal [], @verification_errors
end
end
test1.rb
--------
require "selenium"
require "test/unit"
require 'setup1'
class Test1 < Test::Unit::TestCase
def test_1
@selenium.open("/")
@selenium.type "q", "selenium rc"
@selenium.click "btnG"
@selenium.wait_for_page_to_load "30000"
assert @selenium.is_text_present("Results * for selenium rc")
end
end
this runs, but stops when it reaches @selenium.open("/").
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!
--
Posted via http://www.ruby-forum.com/.