Thursday, October 28, 2010

Finding HTML Elements in Watir

TextBox:
   
IE.text_field(how, what)

Button:

IE.button(how, what)

DropDownList:

IE.select_list(how, what)

CheckBox:   

IE.checkbox(how, what)

RadioButton:   

IE.radio(how, what)

HyperLink:   

IE.link(how, what)

Form:   

IE.form(how, what)

Frame:   

IE.frame(how, what)

And many, many more (div, label, image, etc…)…

Test Unit

Test::Unit is a library of Ruby (just like Watir)

It is not technically part of Watir…however it is used regularly to structure tests.

To use Test::Unit in your scripts you ‘require’ it just as you do watir

require ‘test/unit’
require ‘watir’

Test::Unit is a way to organize your code into “tests”

Test::Unit has built in methods called “assertions” that help your tests with validation.

assert(browser.link(:text, “Click Here”).exists?)

The above statement will return a TRUE or FALSE indicating a pass or fail in your test.

Below is the basic code structure of a class in Test unit

require 'test/unit’

    class TC_MyTest < Test::Unit::TestCase
    include Watir

    def setup        #optional
    end            #optional
    def teardown      #optional
    end             #optional

        def test_pass
            assert(something.exists?)
        end
    end 


Watir Recorders

Watir is not a record/playback tool. However, there are several recorders “out there”

WatirMaker:

 It is a utility for Watir test developers which will record actions in a browser. It comes in two flavors: the C# version, and the Ruby version

Watir WebRecorder:

WebRecorder is an action recorder for web applications. A version that creates Watir scripts was released in February 2006. A handy tool to help learn Watir.Free, but not open source

Webmetrics RIA Script Recorder:

The script recorder is a tool to help generate a working watir script that can be used with the Webmetrics Rich Internet Application Monitoring. Webmetrics RIA Monitoring utilizes the open source technology Watir to do performance monitoring.