Dashboard > WET > Customizing show_objects method
WET Log In View a printable version of the current page.
Customizing show_objects method
Added by Raghu Venkataramana, last edited by Raghu Venkataramana on Sep 29, 2006  (view change)
Labels: 
(None)

For any web page you can see the contents of the page in a format that can be easily ported to a WET script by using the show_objects page. For example, on the hands on page (http://wet.qantom.org/handson.html), if you say show_objects, the output is:
Textareas:-
    Browser('title:=Submit a bug').Textarea('name:=Description')
    Browser('title:=Submit a bug').Textarea('name:=Notes')
    Browser('title:=Submit a bug').Textarea('name:=AboutYourself')

TextFields:-
    Browser('title:=Submit a bug').TextField('label:=Name')
    Browser('title:=Submit a bug').TextField('label:=Email')
    Browser('title:=Submit a bug').TextField('label:=Summary')

Buttons:-
    Browser('title:=Submit a bug').Button('value:=Submit Query')

Lists:-
    Browser('title:=Submit a bug').List('label:=Product')
    Browser('title:=Submit a bug').List('label:=Problem Type')

You can simply copy paste any line above into a WET script. The show_objects above makes the assumption that for a TextField, the label attribute for a textfield is the most important one. Each application is different from one another and for a certain application, the above assumption may not be very accurate. For example, your application may tie the name of the textfield closely with the object under test. WET allows you to configure how the show_objects method actually displays the objects on the web page.

 This configuration is done by the definitions in the %QWT_HOME%\object_identification.xml. Let's check the xml definition for TextField in this file and see how the show_objects is controlled by the various definitions in this page:

............
............
    <Object name='TextField' type='child'>
        <html_tag>input::text</html_tag>
        <html_tag>input::password</html_tag>
        <wet_map_class>WebEdit</wet_map_class>
        <Identifier type='primary'>
            <attribute>label</attribute>
            <value>
                <ie>self.label</ie>
            </value>
        </Identifier>
        <Identifier type='secondary'>
            <attribute>name</attribute>
            <value>
                <ie>self.name</ie>
            </value>
        </Identifier>
    </Object>
............
............

<Object name = TextField> The name of the object is 'TextField' (which is why you see the definition as Browser(...).TextField(...))
<type=child> This is reserved for future use and doesn't have any significance as of now.
<html_tag>input::text</html_tag>
<html_tag>input::password</html_tag>
The html tag that represents the element when you do a view source. A TextField can either be a <input type = 'text'> or <input type='password'>.
<wet_map_class>WebEdit</wet_map_class> What is the corresponding Web class in WET that is to be used. For example, a textfield element is represented in WET using the WebEdit class, a html table is represented using the WebTable class and so on.
<Identifier type='primary'>
            <attribute>label</attribute>
            <value>
                <ie>self.label</ie>
            </value>
        </Identifier>
Each element can have one primary identifier and zero or more secondary identifiers. This actually defines how the element will be identified dynamically during run time. First the show_objects method tries to identify the element using the primary attribute. If the primary attribute for the element is not defined, then show_objects tries to find the element's secondary attribute(s). In this syntax the <attribute>blah</attribute> tells show_objects what the name of the attribute is in the Object("name:=value") syntax.
The <value><ie>self.label</ie></value> tells show_objects how the value is computed. As of now, only <ie> can be used. Later on, when support is added for other browsers, you will be able to add definitions for other browsers too. Here self.label instructs show_objects that after you have created a corresponding WebEdit instance for the html object, call the label method on this instance to determine the value.
<Identifier type='secondary'>
            <attribute>name</attribute>
            <value>
                <ie>self.name</ie>
            </value>
        </Identifier>
    </Object>
This is exactly similar to the primary identifiers definition. Usually this segment is reached only if show_objects cannot identify the object using the primary identifiers

Tip: You can also force show_objects to explictly show all the defined attributes by calling:
show_objects(nil, true)


Using the above technique, you can edit the object_identification.xml to either change the way that objects are identified or even make show_objects to display other elements (provided the element has a corresponding WET class). For example, if a html table element is usually of great significance to you, you can add the definition for the table element in the object_identification.xml file.

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators