Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Once the script locates the QTP wrapper object for the Nexaweb component, it uses the Object propery to access the actual component. It then calls the getScriptObject() method on the actual component. The getScriptObject() method returns the Test Script Object for that object. The script can store the returned Test Script Object in a variable for later use in the test script.  


 

Tip
titleHelpful Tip

Quck Test Pro uses an object repository for storing the objects it uses to build its scripts. To access the Object Repository, select the "Tools/Object Repository...". For example, the object heirarchy of the Object Repository for the previous example would look as follows:

        

 


The find object methods of the Application Script Object

...

The following test script gets the text and value of each list item.  It first gets a vector containing all the list items of the listbox.  It then gets each list item from the vector retrieving the text and value of each list item. 


Code Block
Set listitems = listBox.getListItems() For i = 0 to listitems.size() - 1 Set li = listitems.valueAt( i ) text = li.getText() val = li.getValue() Next

...

The MCO sets the text of the label to the value of the combobox's onCommand() event.

Code View source file

The QTP Test Script

The test first verifies the initial state of the combobox and the label. It then selects each item of the combobox. After each selection, it tests the text of the combobox against the text of the item being selected. It also tests the text of the label against the value of the item being selected.

Visual Basic View source file

Since you can make the combobox an editable component, the ComboBoxScriptObject exposes methods for testing this.  

...

The MCO sets the text of the label to the value of the combobox's onCommand() event. 

Code View source file

The QTP Test Script

The test script first double clicks the combobox to select the text in the textfield. Next, it enters the new text and fires the enter key to end editing and fires the onCommand() of the combobox.  The test ends by checking the text in the label to ensure that it was set to the value entered into the combobox.

Visual Basic View source file

Testing the Tree

Testing the tree is similar to testing the listbox; however, verying the contents and selecting items is more complex, since each row of the tree can have sub-rows. 

...

The following example selects a sub row of the tree, two levels down:

The XML UI

 


Code Block
languagehtml/xml
linenumberstrue
<nxml>
    <rootPane>
      <tree id="MultiRowTree">
        <column/>
        <column/>
        <row>
          <cell text="Multi Item Row Item 1" value="first"/>
          <cell text="Multi Item Row Item 2" value="scond"/>
          <row>
            <cell text="Sub Row 2 Item 1" value="SubItem 3"/>
          </row>
          <row>
            <cell text="Sub Row 1 Item 1" value="SubItem 1"/>
            <cell text="Sub Row 1 Item 2" value="SubItem 2"/>
            <row>
              <cell text="Sub Sub Row 1 Item 1" value="Sub SubItem 1"/>
              <cell text="Sub Sub Row 1 Item 2" value="Sub SubItem 2"/>
            </row>
            <row>
              <cell text="Sub Sub Row 2 Item 1" value="Sub SubItem 3"/>
            </row>
          </row>
        </row>
        <row>
          <cell text="Tree Item 2" value="Item 2"/>
        </row>
        <row>
          <cell text="Tree Item 3" value="Item 3"/>
        </row>
      </tree>
    </rootPane>
  </nxml>

...

For each item, the script gets the text and value, selects the item, then compares the text and value against the text and value of the selected item.

Visual Basic View source file

Testing the Table

The most common table test scenarios include getting and setting values of cells.

...

Code Block
languagehtml/xml
linenumberstrue
 <nxml>
  <rootPane>
    <table id="EditTable" selectionMode="singleCell">
      <column>
        <header text="Column #1"/>
      </column>
      <column>
        <header text="Column #2"/>
      </column>
      <row>
        <cell text="Tree Item 1"/>
        <cell text="editable cell" editable="true"/>
      </row>
      <row>
        <cell text="Sub Tree Item 1"/>
        <cell text="Sub Tree Item 1"/>
      </row>
      <row>
        <cell text="Sub Tree Item 2"/>
        <cell text="Sub Tree Item 2"/>
      </row>
      <row>
        <cell text="Tree Item 2"/>
        <cell text="Tree Item 2"/>
      </row>
    </table>
  </rootPane>
</nxml>

The QTP Test Script

Visual Basic View source file

Advanced Testing

The Test Script API also provides mechanisms for testing more advanced scenarios such as working with right mouse context menus, dialogs, tooltips and even drag and drop. This section provides examples of how to use the Test Script API to test some the more advanced scenarios.

...

Code Block
languagejava
linenumberstrue
import com.nexaweb.client.mco.AbstractMco;
import com.nexaweb.xml.Element;

public class MenuTestMCO extends AbstractMco
{
     public void handleMenuCommand( Element textField, String newValue)
     {
          textField.setAttribute("text", newValue);
     }
 
     public void handleCBStateChange( Element checkBoxItem,
           Element textField )
     {
          String check = checkBoxItem.getAttribute( "selected" );
          if( check == null )
          {
               check = "false";
          }
          textField.setAttribute( "text",
             "CheckBox MenuItem State " + check );
     }
}

The QTP Script

Visual Basic View source file

The following example demonstrates how to use the menus as defined in the XML UI to test the runtime menus. This test is built against the same XML UI and MCO from the first menu example.

The QTP Script

Visual Basic View source file

Testing Context Menus

Context menus are the popup menus that are hooked to the right mouse of a UI component. The following example demonstrates testing a popup menu that is brought up as a right mouse context menu of a label.

...

Code Block
languagejava
linenumberstrue
import com.nexaweb.client.mco.AbstractMco;
import com.nexaweb.xml.Element;

public class ContextMenuHandler extends AbstractMco
{
     public void handleMenuCommand( Element textField, String newValue)
     {
          textField.setAttribute("text", newValue);
     }
} 

The QTP Script

Visual Basic View source file

Testing Tooltips

You can define tooltips for components either as a simple text string or as a predefined popup (for example,  a panel consisting of four labels).  You can retrieve the tooltip using the getTooltip() method of the ApplicationScriptObject.  This method returns a PopupScriptObject, a panel for containing the objects that make up the tooltip. The PopupScriptObject has the following methods that make it easier to work with basic text tooltips:

...

Code Block
languagehtml/xml
linenumberstrue
 <nxml>
  <defs>
    <popup id="custompopup">
      <flowLayout orientation="vertical"/>
      <label text="east"/>
      <label text="north"/>
      <label text="south"/>
      <label text="west"/>
    </popup>
  </defs>
  <rootPane>
    <button text="Text Tooltip" tooltip="This is a button tooltip."/>
    <button text="Popup Tooltip" tooltip="#custompopup"/>
  </rootPane>
</nxml>

The QTP Test Script

Visual Basic View source file

Testing Windows

To test a window, you need to be able to work with the title bar and the contents that make up the window. The following WindowScriptObject methods allow access to the title bar as well as the maximize, minimize and close buttons:

...

Code Block
languagejava
linenumberstrue
import com.nexaweb.client.mco.AbstractMco;
import com.nexaweb.xml.Document;
import com.nexaweb.xml.Element;

public class WindowTestHandler extends AbstractMco
{
    public void buttonOnCommand( Element label, String value )
    {
        Document document = getSession().getDocumentRegistry().
             getUiDocument();
        synchronized ( document.getDomSynchronizationObject())
        {
            label.setAttribute( "text", value );
        }
    }
}

The QTP Test Script

Visual Basic View source file

Testing Dialogs

A dialog is a special window that by default does not have a maximize or minimize button and that you can set to be modal. A modal dialog does not release the input focus while it is open. 

...

Code Block
languagehtml/xml
linenumberstrue
<nxml>
  <declarations xmlns="http://nexaweb.com/mco">
    <mco id="dialogHandler" src="DialogTestHandler"/>
  </declarations>
  <rootPane id="rootPane">
    <button id="button" text="add dialog" 
          onCommand="mco://dialogHandler.addDialog(rootPane)"/>
  </rootPane>
</nxml>

The MCO

Code View source file

The QTP Test Script

Visual Basic View source file

A message dialog is a special dialog used to display a message with icons and buttons.

...

The test will first get the message dialog then test the message and the buttons.   Finally closing the dialog by clicking the OK button.

Visual Basic View source file

Testing Tab Panes

A tab pane is a component that allows other components to share the same space. The tabs control the visible content.  The visible component is the one associated with the selected tab.  Although any component may be associated with a tab, typically a panel is the component associated with it.  The following table describes the TabPaneScriptObject methods for accessing the tabs:

...

Code Block
languagehtml/xml
linenumberstrue
 <nxml>
 <rootPane>
  <tabPane height="200" width="400">
   <tab text="Tab 1">
    <label text="first tab"/>
   </tab>
   <tab text="Tab 2">
    <panel>
     <label text="Tab 2 Child 1"/>
     <label text="Tab 2 Child 2"/>
     <label text="Tab 2 Child 3"/>
     <label text="Tab 2 Child 4"/>
     <label text="Tab 2 Child 5"/>
    </panel>
   </tab>
   <tab text="Tab 3">
    <label text="third tab"/>
   </tab>
  </tabPane>
 </rootPane>
</nxml>

 The Test Script

Visual Basic View source file

Testing Button Groups

A button group is a group of radiobuttons or checkboxes.  Only one checkbox or radiobutton may be selected within the group.  

...

Code Block
languagehtml/xml
linenumberstrue
<nxml>
  <rootPane>
    <panel borderWidth="1">
      <flowLayout orientation="vertical"/>
      <radioButton text="Radio 1" group="group1" selected="true"/>
      <radioButton text="Radio 2" group="group1" selected="false"/>
      <radioButton text="Radio 3" group="group1" selected="false"/>
      <radioButton text="Radio 4" group="group1" selected="false"/>
    </panel>
  </rootPane>
</nxml> 

The Test Script

Visual Basic View source file

Testing Footer Rows

A footer row is a special row that is always drawn on screen at the bottom of a table, tree, or tree table in any vertical scroll position.  A user cannot select this row, navigate to it with the keyboard, expand it, edit or otherwise interact with it; it is for display purposes only.  It is commonly used, for example, to display summation data for the table as a whole.

...

This test script gets the footer row and checks the value of the two lables contained by the footer row.

Visual Basic View source file


Tip
titleHelpful Tip

Prior to Nexaweb Platform 4.5.7, the <ui-test> flag in nexaweb-client.xml has to be true in order to use test script classes.  In 4.5.7 and later versions, these classes are accessible via a plug-in jar file and can be used with this flag being true or false.  If it is set to false, obfuscated Nexaweb client jars will be used and the JavaObject object in QTP will get a name that is not the client class name.  Please see 4.5.7 release notes for more information.

...



Nexaweb

by John Griffith