Search This Blog

Saturday, October 9, 2010

Why Watir?


Why Watir?

  • It’s a free Open Source tool. There are no costs to use the tool.
  • There’s a very active and growing community behind it.
  • It uses Ruby, a full-featured modern scripting language, rather than a proprietary vendorscript.
  • It supports your web app no matter what it is developed in.
  • It supports multiple browsers on different platforms.
  • It is powerful and easy to use, yet beautifully lightweight.

What is Watir (Web Application Testing in Ruby)


Watir is a toolkit used to automate browser-based tests during web application development.
Is an open-source (BSD) family of Ruby libraries for automating web browsers
“Watir drives browsers the same way people do. Watir also checks results, such as whether expected text appears on the page.”
This automated test tool uses the Ruby (programming language) scripting language
  • Internet Explorer,
  • Mozilla Firefox,
  • Google Chrome and
  • Safari (web browser)
Available as a RubyGems gem
Watir operates differently than HTTP based test tools, which operate by simulating a browser. Instead Watir directly drives the browser through the Object Linking and Embedding protocol, which is implemented over the Component Object Model (COM) architecture

Thursday, September 23, 2010

How to get Child Objects?


We can use description object to get all the objects on the page that matches that specific description. Suppose we have to check all the checkboxes present on a web page. So we will first create an object description for a checkboxe and then get all the checkboxes from the page

Dim obj_ChkDesc

Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”

Dim allCheckboxes, singleCheckBox

Set  allCheckboxes = Browse(“Browser”).Page(“Page”).ChildObjects(obj_ChkDesc)

For each singleCheckBox in allCheckboxes

      singleCheckBox.Set “ON”

Next

The above code will check all the check boxes present on the page. To get all the child objects we need to specify an object description i.e. we can’t use the string arguments that will be discussed later in the 2nd way of using the programming description.

Possible Operation on Description Object

Consider the below code for all the solutions
Dim obj_ChkDesc

Set obj_ChkDesc=Description.Create
obj_ChkDesc(“html tag”).value = “INPUT”
obj_ChkDesc(“type”).value = “checkbox”

Q: How to get the no. of description defined in a collection
A: obj_ChkDesc.Count ‘Will return 2 in our case

Q: How to remove a description from the collection
A: obj_ChkDesc.remove “html tag” ‘would delete the html tag property from the collection

Q: How do I check if property exists or not in the collection?
A: The answer is that it’s not possible. Because whenever we try to access a property which is not defined its automatically added to the collection. The only    way to determine is to check its value that is use a if statement “if obj_ChkDesc(“html tag”).value = empty then”.

Q: How to browse through all the properties of a properties collection?
A: Two ways
      1st:
                  For each desc in obj_ChkDesc
                              Name=desc.Name
                              Value=desc.Value
                              RE = desc.regularexpression
                  Next
      2nd:
                  For i=0 to obj_ChkDesc.count - 1
                              Name= obj_ChkDesc(i).Name
                              Value= obj_ChkDesc(i).Value
                              RE = obj_ChkDesc(i).regularexpression
                  Next

2.      By giving the description in form of the string arguments.

You can describe an object directly in a statement by specifying property:=value pairs describing the object instead of specifying an object’s
name. The general syntax is:

TestObject("PropertyName1:=PropertyValue1", "..." , "PropertyNameX:=PropertyValueX")

TestObject—the test object class could be WebEdit, WebRadioGroup etc….

PropertyName:=PropertyValue—the test object property and its value. Each property:=value pair should be separated by commas and quotation
marks. Note that you can enter a variable name as the property value if you want to find an object based on property values you retrieve during a run session.

Consider the HTML Code given below:


Now to refer to the textbox the statement would be as given below

Browser(“Browser”).Page(“Page”).WebEdit(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”

And to refer to the radio button the statement would be as given below

Browser(“Browser”).Page(“Page”).WebRadioGroup(“Name:=txt_Name”,”html tag:=INPUT”).set “Test”

If we refer to them as a web element then we will have to distinguish between the 2 using the index property

Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html tag:=INPUT”,”Index:=0”).set “Test” ‘ Refers to the textbox
Browser(“Browser”).Page(“Page”).WebElement(“Name:=txt_Name”,”html tag:=INPUT”,”Index:=1”).set “Test” ‘ Refers to the radio button


Hierarchy of test description


When using programmatic descriptions from a specific point within a test object hierarchy, you must continue to use programmatic descriptions
From that point onward within the same statement. If you specify a test object by its object repository name after other objects in the hierarchy have
Been described using programmatic descriptions, Quick Test cannot identify the object.

For example, you can use Browser(Desc1).Page(Desc1).Link(desc3), since it uses programmatic descriptions throughout the entire test object hierarchy.
You can also use Browser("Index").Page(Desc1).Link(desc3), since it uses programmatic descriptions from a certain point in the description (starting
from the Page object description).

However, you cannot use Browser(Desc1).Page(Desc1).Link("Example1"), since it uses programmatic descriptions for the Browser and Page objects but
then attempts to use an object repository name for the Link test object (QuickTest tries to locate the Link object based on its name, but cannot
locate it in the repository because the parent objects were specified using programmatic descriptions).