博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
watir测试报告(一)
阅读量:4052 次
发布时间:2019-05-25

本文共 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/

你可能感兴趣的文章
IP报文格式学习笔记
查看>>
autohotkey快捷键显示隐藏文件和文件扩展名
查看>>
Linux中的进程
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
自然计算时间复杂度杂谈
查看>>
当前主要目标和工作
查看>>
使用 Springboot 对 Kettle 进行调度开发
查看>>
一文看清HBase的使用场景
查看>>
解析zookeeper的工作流程
查看>>
搞定Java面试中的数据结构问题
查看>>
慢慢欣赏linux make uImage流程
查看>>
linux内核学习(7)脱胎换骨解压缩的内核
查看>>
以太网基础知识
查看>>
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
Homebrew指令集
查看>>