Open source web testing tool
The future of automated web testing is open source

API Guide - Browser

Courses in c#, ruby, shell scripting, Software testing courses and more

See a video tour
Thwameva technologies offers a state of the art advanced training using multimedia video mentoring , practical oriented training and experts as mentors(*). Thwameva offers software testing courses, courses in WET, ruby, C#, shell scripting and more...
The unique combination of video mentoring by experts and mentor assisted training programs are applicable only for software training courses in Thwameva's Bangalore office.

Thwameva technologies is the primary sponsor for the WET project
 
Main       Web Objects       Win Objects       Test Mgmt       Others      

A Browser object is the reference of the internet explorer window (currently IE is the only supported browser). This is probably the most common object that you would use in all your scripts. There are two ways to create a Browser object: a) Create a new empty browser - In this case a new browser is launched b) Attach to an existing browser - In this case the scripts attach to a browser that is already running on the system.

Methods

Methods Inherited from WebContainer

Button   Checkbox   File   IFrame   Image   Link   List   Radio   Table   TextField   Textarea   button   checkbox   div   element_by_tagname   file_field   iframe   image   link   p   radio   select_list   span   table   text_field   textarea  

Common methods for all web elements. This module is inserted into all Web objects as a mixin.

Methods Inherited from WebObject

browser   exists?   fire_event   id   index   is_exist   name   tag_name  

Public Class methods

Checks to see if a Browser with the given parameters is running on the system. The parameters is a hashtable of expected name value pairs. For example, if you want to check if a browser with the title of ‘google’ is running, you have to say

 Browser.is_exist('title' => 'Google')

Create a new instance of the browser. The most common way of using it is by not specifying any parameters :

     Browser.new()

In the above case, a new browser is launched. If the optional boolean value is set to ‘true’, then a WET Browser object is created but a real browser is not started.

Action:

1) Create a new ruby script with the following lines

 #####################################
 require 'WET'
 include WET
 ie = Browser.new()
 #####################################

2) Save the ruby script and execute it.

Result:

A new blank IE window opens up.

Tip:

Everytime you run the above script, a new browser window is opened. Close this browser window manually or in a short time, you’ll have 10s of IE windows open on your desktop.

Public Instance methods

    Get a modal dialog that is owned by this browser. The Dialog can be
    retreived by searching for one or more parameters. The argument
    supplied is a name value pair of expected properties of the modal dialog
    in the form of "name:=value". Currently you can only specify the 'title'
    property - that is, "title:=my_dialog_title"
    Modal Dialogs are the popups that are shown within applications - eg. Are You Sure?, Security Information, etc., When these popups are displayed, you will not be allowed to work on the parent window unless the popus are closed. ModalDialogs are referenced by calling the Browser's Dialog method.

 (1)  Getting a reference of the required Modal Dialog
      The syntax to get the reference of a Modal Dialog is :
      Browser.Dialog("name:=value")
      Where name is the name of the attribute to be checked.
      value is the value of that attribute.

   Example
     Browser('title:=Controls').Dialog('title:=Microsoft Internet Explorer')

     In the current version, the only attribute that can be used is:title
     The title displayed on the Modal Dialog

Actions:

      1)Open a new script and type the following:

 #####################################
 require 'WET'
 include WET
 ie = Browser.new()
 ie.goto "http://wet.qantom.org/userguide/browser_sample.html"
 ie.Button("value:=Alert").click_without_blocking
 dlg = ie.Dialog("title:=Microsoft Internet Explorer")
 puts dlg
 #####################################

Result:

After running this script, the sample browser page is opened, the ‘Alert’ button is automatically clicked and the sample popup window is opened as a result. The following text is printed out on the console:

Dialog(text:=Microsoft Internet Explorer)

If you notice, the text printed is nothing but the title displayed on the popup window.

Tip : In the above script observe that you typed Button.click_without_blocking and not Button.click. The reason for doing this is that if use ‘click’, then as soon as the popup window is opened, it puts the browser into a ‘wait’ state and nothing else can work, till the popup window is dismissed. You probably would have put code in the subsequent lines to handle this popup window. Unfortunately since the browser is waiting (and since your test scripts are the ones that are driving the browser, your script is waiting in turn) forever and nothing happens. When you use click_without_blocking, then the click operation is carried out in a separate process and therefore allows your script to immediately move to the next line. If you expect that peforming a click operation is likely to open a modal popup dialog, then use click_without_blocking() and not click()

    Get a frame with the specified properties. The properties are
    specified as name-value pairs using the syntax:
        "property_name:=value"
    The value can either be a string literal or a string representing
    a regular expression. To emulate a regular expressioin, the value
    starts and ends with the '/' character. For example,
    "name:=/some.*/"

   For those web pages that are displayed in a frameset, WET's Frame object can be used to get a reference of the Frame. To find out all the frames shown in a Browser, you need to use the Browser's show_frame method.

   1) Getting a reference of the required Frame
    The syntax to get the reference of a Frame is :
    Browser.Frame("name:=value")
    Where name is the name of the attribute to be checked.
    value is the value of that attribute.

Example

    Browser('title:=Controls').Frame('name:=fr001')

    The commonly used attributes to identify an Image are:
    text   The text of this Frame
    name          The HTML name attribute of the frame
    id     The HTML id attribute of the frame

Actions:

  1) Write the following script in a new ruby file
   #####################################
     require 'WET'
     include WET
     ie = Browser.new()
     ie.goto "http://www.wet.qantom.org/userguide/frameset.html"
     tf = ie.Frame('name:=top')
     puts tf.text
   #####################################

   2) Execute this script

Result:

    The following output should be printed on the console

    THIS IS THE TOP FRAME

     The different properties that can be used to identify a frame
     are:

    * name - The html name attribute of the frame
    * id      - The html id attribute of the frame
    * index  - The order in which this frame appears on the web page.

Find all the children of this Browser. When doing so, recurse into in any other top level containers (Frames / IFrames) and get the children of these containers too. The boolean parameters dictates if a refresh tree is required. If not specified or specified as false, then the previously cached array of children (If cached earlier) is returned. Otherwise, the whole tree is traversed again.

Check to see if a modal dialog exists for this browser. The method can be called without any parameters or with a hashtable of expected properties. If called without any argument, then it checks to see if the browser has any open modal dialog at all. If called with a hashtable of parameters, then check to see if there is a modal dialog with the properties matching the hashtable. Example. If called as ie.check_dialog_exists({"title" => "Microsoft Internet Explorer"}) then this method checks if a modal dialog with the title of ‘Microsoft Internet Explorer’ is active. Note: You can also call the method with a series of ‘name:=value’ parameters instead of a hashtable. However this method is deprecated and should not be used in new scripts.

Check to see if the expected text matches the text of the control.The text of a browser is the full text displayed in the document of the browser.The search_text can either be a string literal or a regular expression.

If the check is successful prints a success statement to the report,otherwise reports failure.

Check to see if the text displayed by the browser does not match expected_text.This kind of check is useful either when you need to ensure that a certain text doesn’t exist.For example,when doing a negative test or after doing a delete operaion,you need to confirm that the text actually has been deleted.

If the check is successful (that is,the text confirmed to be not found) Pritns a success statement to the report,otherwise reports a failure.

Close the IE Browser window represented by this instance

Get the count of the total number of elements in this browser. The count is the sum of all children of this browser (recursively) and the browser itself

Get properties of dom elements as a hashtable starting off from the ‘start’ parameter and a total of no more than ‘length’ parameter. This method is used by the remote C# layer when it needs to asynchronously update the browser view. To make the update appear much faster, the client requests the dom elements in multiple parts, rather than as a single block. For example, if there are 100 objects on the page, the c# client requests for 10 at a time. When it recieves 10, it updates the information on its simulated browser. It then goes and makes a request for another 10 and updates. This continues till all the objects are updated. Since the user can start using some part of the application even before all the objects are downloaded, working with the application appears to be much faster.

Is the browser actually displaying a page without any errors? Return true if it does exist. False otherwise.

frame(*props)

Alias for Frame

The goto command is used to navigate to a web page. The parameters to be passed to this method are:

 (1) url  The url of the web page that you want the browser to navigate to
 (2) process_type (optional)  You can specify whether the script should wait for the page to load before moving on to the next line or not. The default (when parameter is not specified) is to wait for the page to completely load. In certain cases, it may be required to just make a request for the browser to navigate to a page and then carry on with the next lines of script. This is usually true when the first result upon navigating to a web page is to see a modal popup window. In such a case, you can set the second parameter to OUTOFPROCESS and the subsequent lines of scripts wont be blocked

Example:

 ie.goto  "page_to_be_opened"
 ie.goto "a_page_that_opens_dialog_upon_navigating", OUTOFPROCESS

Actions:

1) Open the previous script and add the following line to the end of the script

    ie.goto "http://www.google.com"

The complete script looks like:

 #####################################
 require 'WET'
 include WET

 ie = Browser.new()
 ie.goto "http://www.google.com"
 #####################################

Now run this ruby script

Result:

This time, a new IE window is opened and this window automatically navigates to the google web site. (As before, close the IE window manually, after script execution)

Get the html of the page that is being displayed in this browser.

is_exist()

Alias for exists?

Print all the ‘wet’ objects displayed in the browser. Not only are the direct children of the

       browser displayed, but also the children of top level parents like frames & iframes.
       Get the text displayed on the browser.

The text() command prints out the text displayed by the modal dialog.

Get the title of the browser as displayed on the title bar

Get the URL of the page that this browser is displaying.

Get the win32 window handle of the browser

Attributes

container  [R] 

Public Instance methods

Find a Button with the specified properties, The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The common properties used to identify a button are :

  • name - The html name attribute of the button
  • id - The html id attribute of the button
  • value - The value of the button is the text displayed on the button.

Find a Web checkbox with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a checkfield are:

  • name - The html name attribute of the checkbox
  • id - The html id attribute of the checkbox
  • label - The checkbox’s label. The checkbox’s label is the text that is
     displayed to the left of the checkbox.
    

Find a Web File with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a File are:

  • name - The html name attribute of the file element
  • id - The html name attribute of the file element
  • label - The File element’s label. The label of a file element is the
     text displayed to the left of the file.
    

Find an IFrame with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a Textarea are:

  • name - The html name attribute of the text area
  • id - The html id attribute of the text area.
  • text - The text contained in the IFrame

Find an Image with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The common properties for an image are

  • id - The html id attribute of the image
  • src - The source path

Get a web Link with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

For a link the following are the commonly used properties:

  • id - The html id attribute of the link
  • text - Text that is displayed for the link.
  • href - Url to which this link points to

Find a Web List with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a List are:

  • name - The html name attribute of the web list
  • id - The html id attribute of the web list.
  • label - The Lists’s label. A lists label is the text that is
     displayed to the left of the weblist
    

Find a Web radio button with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a radio button are:

  • name - The html name attribute of the radio button
  • id - The html id attribute of the radio button
  • label - The radio button’s label. In the case of a radio button, the
     label is considered to be the textimmediately after the radio.
    

Find a HTML Table with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties with which a table can be identified are:

  • id - The html id of the table
  • text - This is a very useful way to identify a table. Sometimes the only
     info that is available about a table is the text contained in the table.
     The table's text is the aggregate of the contents of the cells of the table.
    

Find a Web textfield with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a textfield are:

  • name - The html name attribute of the Textfield
  • id - The html id attribute of the Textfield
  • label - The textfield’s label. The textfield’s label is the text
     displayed to the left of the textfield.
    

Find a Textarea with the specified properties. The properties are specified as name-value pairs using the syntax:

    "property_name:=value"

The value can either be a string literal or a string representing a regular expression. To emulate a regular expressioin, the value starts and ends with the ’/’ character. For example, "name:=/some.*/"

The properties used to identify a Textarea are:

  • name - The html name attribute of the text area
  • id - The html id attribute of the text area.
button(*props)

Alias for Button

checkbox(*props)

Alias for Checkbox

Get an element which is of the ‘div’ tag.It is equivalent of saying - element_by_tagname(‘div’, props)

Get an element based on the tagname. This is useful for those cases where there is no predefined WET class for a particular tag but a scripter needs to use it.

  • tag_name = Name of the tag, eg. p, div, etc.,
  • props = Hashtable of name-value properties for searching.

For example if you want to get a <div> element whose id is ‘myId’, then you can say

    element_by_tag_name("div", "id" => "myId")
file_field(*props)

Alias for File

iframe(*props)

Alias for IFrame

image(*props)

Alias for Image

link(*props)

Alias for Link

Get an element which is of the ‘p’ tag.It is equivalent of saying - element_by_tagname(‘p’, props)

radio(*props)

Alias for Radio

select_list(*props)

Alias for List

Get an element which is of the ‘span’ tag.It is equivalent of saying - element_by_tagname(‘span’, props)

table(*props)

Alias for Table

text_field(*props)

Alias for TextField

textarea(*props)

Alias for Textarea

Public Instance methods

Get the WebBrowser object which hosts this element

Check to see if the object exists or not at runtime.

Returns true if the object exists, false if it doesn’t

Emulate firing an event - For example - moving mouse over, etc,.

Get the ‘id’ attribute that is associated with this element

Get the index of this element w.r.t its container.

is_exist()

Alias for exists?

Get the ‘name’ attribute that is associated with this element

Get the html tag of this element. For example: <input> for textfield, <img> for image, etc.,

 

WET is a opensource automated web testing tool which uses Watir as the library to drive web pages. WET drives an IE Browser directly and so the automated testing done using WET is equivalent to how a user would drive the web pages. WET extends the scripting abilities of Watir and also offers the convenience of recorders. It is licensed under LGPL and BSD style open source licenses.

WWW wet.qantom.org
Search powered by Google