Web Application Testing in Ruby: How to Create watir Frame work : Customer Module.rb
require 'test/unit'
02 include Test::Unit::Assertions
03
04 module Admin
05 TITLE = 'ADMINISTER Pragprog Books Online Store'
06 URL = 'http://localhost:3000/admin/'
07
08 def Admin.log_on(browser, username, password)
09 browser.goto(URL)
10 if browser.link(:text,'Log out').exist? then #if already logged in
11 browser.link(:text,'Log out').click
12 end
13 browser.text_field(:id, 'user_name').set username
14 browser.text_field(:id, 'user_password').set password
15 browser.button(:value, ' LOGIN ').click
16 if browser.div(:id, 'notice').exist? then
17 return false,browser.div(:id, 'notice').text
18 else
19 return true,''
20 end
21 end
22
23 def Admin.ship_items(browser, name)
24 browser.goto(URL)
25 browser.link(:text, 'Shipping').click
26 num_orders = 0
27 index = 0
28 browser.form(:action,'/admin/ship').divs.each do |div|
29 if div.class_name == "olname"
30 index+=1
31 if div.text == name then
32 browser.form(:action,'/admin/ship').checkbox(:index, index).set
33 num_orders+=1
34 end
35 end
36 end
37
38 browser.button(:value, ' SHIP CHECKED ITEMS ').click
39
40 if num_orders == 1 then
41 assert_equal(browser.div(:id,"notice").text, "One order marked as shipped","Correct notice")
42 elsif num_orders > 1 then
43 assert_equal(browser.div(:id,"notice").text, "#{num_orders} orders marked as shipped","Correct notice")
44 end
45 return true, num_orders.to_s
46 end
47
48 end
No comments:
Post a Comment