first post here. I’m a novice programmer as you’ll see, and I’m learning to use Ruby to write automated functional tests. I generated the source below from Selenium IDE and I’ve been tinkering with it but I don’t understand why this code runs without instantiation or method calls.
require 'rubygems'
require "selenium-webdriver"
require "test/unit"
DataDir='Users/CH/src/ruby/data'
class Case1 < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :firefox
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
def teardown
#@driver.quit
assert_equal [], @verification_errors
end
def test_case1
@root_url="http://www.google.com"
@driver.get @root_url+"/#sclient=psy-ab&hl=en&biw=1440&bih=716&source=hp&q=Test&pbx=1&oq=Test&aq=f&aqi=g4&aql=&gs_sm=e&gs_upl=3631l4283l0l4700l4l4l0l0l0l0l272l860l0.2.2l4l0&bav=on.2,or.r_gc.r_pw.r_cp.,cf.osb&fp=10e90fa4cbd35dc9"
@driver.find_element(:id, "lst-ib").clear
@driver.find_element(:id, "lst-ib").send_keys "test"
end
def element_present?(how, what)
@driver.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def verify(&blk)
yield
rescue Test::Unit::AssertionFailedError => ex
@verification_errors << ex
end
end
Sorry if it’s a hopelessly n00b question but no amount of Googling has helped answer it.
Because
test/unit(actuallyminitest/unitif you’re on Ruby 1.9.x) contains the code to execute the test cases that you define. You can browse around the source here and here if you like, to see how it’s done. Essentially therequire 'test/unit'line will ultimately call theautorunmethod on Test::Unit, which knows how to run your tests.