多思考,多实践,现状才会改变!

ruby watir 自动化单元测试 截图操作

上一篇 / 下一篇  2011-07-18 22:27:08 / 个人分类:文件代码

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,"pasLast0").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
 

TAG: Capture Screen test Test Unit Watir watir 截图

引用 删除 wodetianxia   /   2012-08-08 10:55:17
请问一下:in `require':cannot load such file -- watir/screen_capture (LoadError)我加了require 'rubygems'还是不可以
我还需要安装什么
荒漠赤沙——的个人空间 引用 删除 jingwdongw   /   2011-10-11 17:17:51
原帖由山东白水泉于2011-10-11 11:55:00发表
嗨,  请问这个例子你试过了吗??

    参考他的截屏调用方法做的截屏,用的还好,不知道你参考的点是哪方面。
山东白水泉 引用 删除 山东白水泉   /   2011-10-11 11:55:00
嗨,  请问这个例子你试过了吗??
 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

Open Toolbar