> Are you in the process of developing any framework using the watir ?
> If yes, can you send some information about it ?
With every test case, I write a Test Class
An example:
class ST_LTD_3
def initialize
$log.test_info(self.class, 'Select Depot which has territories and
click search',
'All matching territories are
displayed')
string_to_search = ["DF1", "MA Portfolio"]
start_browser
login
goto_territory_list
search_territory("UNITED KINGDOM", "BRISTOL")
click_search
string_to_search.each {|x|
$log.verify_html(x)
}
rescue => e
p "test failed: #{e.message}"
p e.backtrace
ensure
log_out
close_window
end
end
breakdown
$log.test_info(self.class, 'Select Depot which has territories and click
search',
'All matching territories are
displayed')
This logs the test name, a description of the test and the expected result
to an xml file
start_browser
login
each window or area of funtionality is in a module
module Browser
def
start_browser(url='http://gbahevm06l24.gb.tntpost.com:9081/wps/portal')
$ie = Watir::IE.new
$ie.goto(url)
$ie.maximize()
end
end
module Login
def login(username='g126ahe', password='g126ahe')
$ie.link(:text, 'Log in').click
$ie.text_field(:name, /userid/).set(username)
$ie.text_field(:name, /password/).set(password)
$ie.button(:value,'Log in').click
end
def log_out
$ie.link(:text, 'Log out').click
end
end
this logs a pass or fail to the xml log
$log.verify_html(x)
full xml log file
class Logging
def initialize
@doc = Document.new
xmldecl = XMLDecl.default
@doc.add(xmldecl)
@root = @doc.add_element 'testresults'
end
def verify_html(vp_text) #add optional params
if $ie.contains_text(vp_text)
self.test_results('pass')
else
self.test_results('fail', "#{vp_text} is NOT on the page")
end
#do a not here
end
def test_info(test_name, desc, exp)
@test = @root.add_element 'test'
@test.attributes["id"] = test_name
des= @test.add_element 'description'
des.text = desc
res = @test.add_element 'expected'
res.text = exp
end
def test_results(result, *msg)
if result.upcase == 'PASS' then
test_status= @test.add_element 'teststatus'
test_status.text = 'PASS'
elsif result.upcase == 'FAIL' then
fail = @test.add_element 'teststatus'
fail.text = 'FAIL!'
fail_msg = @test.add_element 'failmessage'
fail_msg.text = msg
elsif result.upcase == 'SKIP'
skip = @test.add_element 'teststatus'
skip.text = 'SKIP'
skip_msg = @test.add_element 'skipmessage'
fail_msg.text = msg
end
end
def write_xml_to_file
@doc.write($stdout, 1)
@doc.write(File.open("C:/test_results.xml","w"))
end
end
the xml output is something like this
<testresults>
- <test id="ST_LTD_1">
<description>Check that window displayed is correct</description>
<expected>Correct image is displayed</expected>
<pass>PASS</pass>
</test>
- <test id="ST_LTD_2">
<description>Select to Add an employee in a role</description>
<expected>Employee was assigned to territory successfully</expected>
<fail>FAIL!</fail>
<failmessage>security not implemented gonna fail</failmessage>
</test>
</testresults>
to read in a csv do something like this
def enter_territory
require 'csv'
reader = CSV.open('C:\test_data', 'r')
header = reader.shift
reader.each{|row| next unless row.any?
p row
}
end
the appmap bit, I am going to steal of Bret's suggestion in a previous post
feedback or suggestions welcome
aidy
---------------------------------------------------------------------------------------------------------------
This message and any attachment are confidential and may be privileged or
otherwise protected from disclosure.
If you are not the intended recipient, please telephone or email the sender and
delete this message and any attachment from your system.
If you are not the intended recipient you must not copy this message or
attachment or disclose the contents to any other person.
---------------------------------------------------------------------------------------------------------------
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general