With the Watir testing tool one thing is very necessary that you must have some programming knowledge because Watir is not based on recording and playback concept. In Watir every script is written by tester before running it. If you want to test your web application by Watir then do one thing, open that page which you want to test and open the view source of page. Do you have knowledge about HTML? Because HTML knowledge is very necessary with Watir. If your web contains buttons, text fields, links, drop-down menus then you can write the script for these objects like this-

For Button you can write script like this but take that variable where you have opened IE browser.

variable_name.button(:name, "Button name").click

"Button name" this value should use according to source code.

variable_name (variable name)

button (Class name)

name (name of button)

Button name (name of button which is used in coding).

this syntax will click your button which is present on web page.

For text box.

variable_name.text_field(:name, "text box name").set ("Asit")

.set (this syntax will put your desired word in text box)

For hyper links.

variable_name.link(:text, "link name").click

.click (this syntax will tell to Watir that click link).

For drop down box.

variable_name.select_list(:name, "drop down box name").select ("drop down value")

.select (this syntax will tell to Watir that select drop down values).

So these are some scripts which I have described and I'll come with further discussions about Watir.

Advertisements

10 thoughts on “How to write test script in Watir

  1. Hi Mayank, really good job!! It really works. By using these kind of script the tester can save her precious time. But what if the web page has more than one hyper links or buttons and the tester wants to click all automatically one by one? I mean tio sat is it possible to put the line:-
    variable_name.link(:text, “link name”).click
    inside a loop and all the links or buttons get clicked one by one. I think you have to consider the page navigation on clicking also. Means on every iteration of the loop the “BACK” button of browser should click to come to the previous page.
    Bye the way I am also trying get the solution.
    Keep it up!!

  2. What about an api that would allow this kind of syntax:

    Page.Control(“text box name”).Text = “Asit”
    Page.Control(“link name”).Click
    Page.Control(“drop down box name”).Value = “drop down value”

    http://www.InCisif.net
    Web Testing With C#, VB.NET or IronPython

  3. Hello
    Can you help me.
    By watir
    How can I get the dropdown’s selected value?
    I need to get the text of the current selected value of the drop down.
    Can u plz provide an example

  4. Hello,

    I am new to Watir. Please let me know, how to write scripts in Watir. I mean in which editor I should write scripts and ow to get that editor. Should I write in a simple text file. Also please let me know how to execute the scripts and get the results. Please do the needful as soon as possible.

    Thanks
    Subhas.

  5. hiim jade and i hope yore having a fantasi stick time and i hope you have found lods of clues?

    from jade p.s i whant to be where you swim with wals ok just whanted you to know ok byexxxxxx

  6. Hey, your blog post saved me going through long tutorials, without me losing any knowledge that matters.
    Thanks.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s