# Ruby and selenium for a newbie

**URL:** <https://www.ruby-forum.com/t/ruby-and-selenium-for-a-newbie/193919>\
**Category:** Ruby\
**Created:** [August 26, 2010, 3:40pm UTC](https://www.ruby-forum.com/t/ruby-and-selenium-for-a-newbie/193919 "2010-08-26T15:40:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bskaggs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ab097/32.png) [@bskaggs](https://www.ruby-forum.com/u/bskaggs)\
**Post date:** [August 26, 2010, 3:40pm UTC](https://www.ruby-forum.com/t/ruby-and-selenium-for-a-newbie/193919/1 "2010-08-26T15:40:45Z")

</div>

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/](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!
