Purpose
Mercury has created a demo site at http://newtours.demoaut.com for its product QTP – Quick Test Pro.
The following codes are tested against the demo site.
What Features?
1, Unit Test
2, Screen Capture
3, Basic IE element identification and operation
Tips
make sure Autoix.dll registered correctly
use FireBug to identify all elements under the site.
Codes
require 'test/unit'
require 'watir'
require 'watir/screen_capture'
class Demo < Test::Unit::TestCase
include Watir
include Watir::ScreenCapture
def setup
@ie = Watir::IE.new_process
@ie.goto("http://newtours.demoaut.com/")
end
def test_logon
@ie = Watir::IE.attach(:url,"http://newtours.demoaut.com/" )
@ie.maximize()
assert_equal(@ie.title, "Welcome: Mercury Tours")
@ie.text_field(:name, "userName").set "test"
@ie.text_field(:name, "password").set "test"
@ie.button(:name,"login").click
screen_capture("logon.jpg",true)
assert_equal(@ie.title, "Find a Flight: Mercury Tours:")
assert(@ie.radio(:name,"tripType", "oneway").exists?)
assert(@ie.select_list(:name,"passCount").exists?)
assert(@ie.select_list(:name,"fromPort").exists?)
assert(@ie.select_list(:name,"fromMonth").exists?)
assert(@ie.select_list(:name,"fromDay").exists?)
assert(@ie.select_list(:name,"toPort").exists?)
assert(@ie.radio(:name, "servClass","Business").exists?)
assert(@ie.select_list(:name,"airline").exists?)
assert(@ie.form(:name, "findflight").exists?)
# booking page 1
@ie.radio(:name,"tripType", "oneway").set
@ie.select_list(:name,"passCount").select "1"
@ie.select_list(:name,"fromPort").select "Acapulco"
@ie.select_list(:name,"fromMonth").select "March"
@ie.select_list(:name,"fromDay").select "10"
@ie.select_list(:name,"toPort").select "Frankfurt"
@ie.radio(:name, "servClass","Business").set
@ie.select_list(:name,"airline").select "Unified Airlines"
@ie.form(:name, "findflight").submit
screen_capture("page1.jpg",true)
# booking page 2
assert(@ie.radio(:name, "outFlight","Blue Skies Airlines$360$270$5:03").exists?)
assert(@ie.radio(:name, "outFlight","Blue Skies Airlines$361$271$7:10").exists?)
assert(@ie.radio(:name, "outFlight","Pangea Airlines$362$274$9:17").exists?)
assert(@ie.radio(:name, "outFlight","Unified Airlines$363$281$11:24").exists?)
@ie.radio(:name, "outFlight","Pangea Airlines$362$274$9:17").set
assert(@ie.radio(:name, "inFlight","Blue Skies Airlines$631$273$14:30").exists?)
@ie.radio(:name, "inFlight","Blue Skies Airlines$631$273$14:30").set
assert(@ie.form(:name,"results").exists?)
@ie.form(:name,"results").submit
screen_capture("page2.jpg",true)
#booking page 3 -- purchase
assert(@ie.text_field(:name,"passFirst0").exists?)
assert(@ie.text_field(:name,"passLast0").exists?)
assert(@ie.text_field(:name,"creditnumber").exists?)
assert(@ie.form(:name,"bookflight").exists?)
@ie.text_field(:name,"passFirst0").set "samuel"
@ie.text_field(:name,"passLast0").set "luo"
@ie.text_field(:name,"creditnumber").set "1234"
@ie.form(:name,"bookflight").submit
screen_capture("page3.jpg",true)
end
def teardown
@ie.close()
end
end