本文共 2478 字,大约阅读时间需要 8 分钟。
本文讲述的是利用watir来生成html报告。
其一: 使用test/unit, 这样结构上看其里比较清晰。
其二: 订制html样式, 这样每次只要套用就可以了。
其三: 本文尚有不足之处。 需不断修改, 以为己用。
require 'test/unit'
require 'watir' require 'html.class' class Google_search_test < Test::Unit::TestCase def setup @browser_type = 'IE' #~ browser_type = 'Firefox' @site = "www.google.com" @test_environment = 'QA' # initialize HTML report @html = HTMLReport.new() # createReport(reportName, header, browser_type) @report = @html.createReport('google_search', 'Google Search', @browser_type) end def test_001 #this method can be set comm method. if @browser_type == 'IE' @browser = Watir::IE.new @browser.goto @site elsif @browser_type == 'Firefox' Watir::Browser.default = 'firefox' @browser = Watir::Browser.start(@site) end ###################################### test_case = @html.newTestName('Verify controls') ###################################### test = 'Step 1: Check search text field' @html.add_to_report(@browser.text_field(:name, 'q').exists?, test, 'PASS: Located search text field', 'FAIL: Unable to locate search field') test = 'Step 2: Check Google Search button' @html.add_to_report(@browser.button(:name, 'btnG').exists?, test, 'PASS: Located Google Search button', 'FAIL: Unable to locate Google Search button') test = 'Step 3: Check Feeling Lucky button' @html.add_to_report(@browser.button(:name, 'btnI').exists?, test, 'PASS: Located Feeling Lucky button', 'FAIL: Unable to locate Feeling Lucky button') ###################################### test_case = @html.newTestName('Perfom Watir search') ###################################### @browser.text_field(:name, 'q').set 'Watir' @browser.button(:name, 'btnG').click test = 'Step 1: Check valid search results (1)' @html.add_to_report(@browser.text.include?('Babysteps in WATIR'), test, 'PASS: Located text "Babysteps in WATIR"', 'FAIL: Unable to locate text "Babysteps in WATIR"') test = 'Step 2: Check valid search results (2)' @html.add_to_report(@browser.text.include?('Project Info'), test, 'PASS: Located text "Project Info"', 'FAIL: Unable to locate text "Project Info"') test = 'Step 3: Check for invalid search results' @html.add_to_report(@browser.text.include?('Suez Canal'), test, 'PASS: Did not locate text "Suez Canal"', 'FAIL: Found text "Suez Canal"') end def teardown # teardown #@browser.close @html.finishReport(@report, @browser_type, @test_environment) rescue => e puts $! puts e.backtrace @html.finishReport(@report, @browser_type, @test_environment) #~ @browser.close end end转载地址:http://dwjci.baihongyu.com/