Você está na página 1de 2

Scripting Web Tests

Watir Cheat Sheet


Getting Started with Watir
require 'watir' ie = Watir::IE.start('http://localhost:8080') ie.close ie = Watir::IE.attach(:title, 'title')

Load the Watir library Start IE using the local timeclock server. Close IE. Attach to an existing IE window, so you can drive it with Watir.

Manipulating Controls with Watir


ie.text_field(:name, 'name').set('value') ie.button(:value, 'value').click ie.button(:name, 'name').click ie.checkbox(:name, 'name').set ie.object(:attribute, 'name').flash

Set the text field specified name specified value. Click the button with the specified value (label) Click the button with the specified name. Check the check box named "name". (Uncheck: clear) Cause the specified control to flash.

A Special Testing Function For Timeclock require 'toolkit/testhook' Delete any database records for the named ensure_no_user_data 'name' user. Accessing Page Contents with Watir ie.contains_text('text') ie.title ie.html ie.table(:id, 'recent_records).to_a ie.table(:id, 'recent_records')[2][1].text Assertions assert_equal(expected, test_method) assert_match(regexp, test_method) assert(expression) Return true if the current page has the specified text somewhere on the page. Otherwise, false. Return the title of the current page. Return all the HTML in the body of the page Return an array containing the text in the table's rows and columns. Return the text from the first column of the second row of the table id'd 'recent_records. Test whether the expected value matches the actual value returned by the test method Test whether the regular expression matches the actual value returned by the test method. Test whether the expression is true.

Scripting Web Tests

Você também pode gostar