Watir Cheat Sheet

rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">

Getting Started with Watir

require 'watir'

Load the Watir library

ie = Watir::IE.start('http://localhost:8080')

Start IE using the local timeclock server.

ie.close

Close IE.

ie = Watir::IE.attach(:title, 'title')

Attach to an existing IE window, so you can drive it with Watir.

 

Manipulating Controls with Watir

ie.text_field(:name, 'name').set('value')

Set the text field specified name specified value.

ie.button(:value, 'value').click

Click the button with the specified value (label)

ie.button(:name, 'name').click

Click the button with the specified name.

ie.checkbox(:name, 'name').set

Check the check box named "name". (Uncheck: clear)

ie.object(:attribute, 'name').flash

Cause the specified control to flash.

 

A Special Testing Function For Timeclock

require 'toolkit/testhook'

ensure_no_user_data 'name'

Delete any database records for the named user.

 

Accessing Page Contents with Watir

ie.contains_text('text')

Return true if the current page has the specified text somewhere on the page. Otherwise, false.

ie.title

Return the title of the current page.

ie.html

Return all the HTML in the body of the page

ie.table(:id, 'recent_records).to_a

Return an array containing the text in the table's rows and columns.

ie.table(:id, 'recent_records')[2][1].text

Return the text from the first column of the second row of the table id'd 'recent_records.

 

Assertions

assert_equal(expected, test_method)

Test whether the expected value matches the actual value returned by the test method

assert_match(regexp, test_method)

Test whether the regular expression matches the actual value returned by the test method.

assert(expression)

Test whether the expression is true.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值