Client Automation

Requires Platform 4.2+

Using QuickTest Professional (QTP) to Test Nexaweb Application Clients

This document describes how to use QTP to test a Nexaweb application client developed with Nexaweb Platform 4.2.x.

You can use QTP to test a Nexaweb application client:

  • Using normal\QTP recording mode
  • By writing scripts

This document covers how to test a Nexaweb application client using normal\QTP recording mode.

Requirements 

  • QuickTest Professional (QTP)
  • QTP Java plug-in, installed and enabled

Setting Nexaweb Application Client Configuration

You can test either the applet client or the destkop client; however, you must test an unobfuscated version of the client.

To test your Nexaweb application client and to ensure your ability to record key events on Abstract Windowing Toolkit (AWT) components, you must edit your Nexaweb application client's configuration file.

To edit your application client's configuration file:

  1. Locate: WEB-INF/nexaweb-client.xml of the application to test.
  2. Open nexaweb-client.xml with a text editor.
  3. To use an unobfuscated client:
    -Locate the following entry: <ui-test>false</ui-test>.
    -Change this entry to true: <ui-test>true</ui-test>.
  4. To ensure your ability to record key events on AWT components, add the following entry as a top-level child of <client-app>:
    <quick-test-pro-record-fix>true</quick-test-pro-record-fix>.
  5. Save and close nexaweb-client.xml.
  6. Restart the server.

Note: A fix for the recording of key events is now available from Mercury. This fix makes the <quick-test-pro-record-fix> setting no longer necessary. To obtain the fix, contact Mercury and request path SR# 1-345639133 with keywords "patch to fix key recording bugs".

Preparing to Record

If you plan to:

  • Check the return value of any method on a Nexaweb component
  • Check the text of text associated Nexaweb components

add the text from NexaQtpLib, a library of script functions, shown at the end of this page as an Associated Library File in QTP.

To add Associated Library File:

  1. Start a new test.
  2. Select Test > Settings > Resources.
  3. Add the NexaQtpLib text as an Associated Library File.
    These functions show up in QTP as Script Library Functions.

Recording

To record:

In either Keyword View or Expert View, position the cursor at the bottom of the script and click Record.

  • To test an applet client:
    - Select the Web tab
    - Select the browser you're using (you should only need to do this once)
    - Select the page to launch (for example http://localhost:8080/internationalizationsample/.
  • To test a desktop client:
    - Select the Java tab
    - Enter the working directory (for example, C:\nexa\client)
    - Enter the command line used to launch (for example, java -cp lib\NexawebInstallClient.jar com.nexaweb.client.desktop.DesktopClient -logFile log.xml -server http://localhost:8080 -appcontext /RichText -initialPage autoime.xml
     

When the application's initial screen appears:

  • Select Insert > Checkpoint > Standard Checkpoint
  • Click on an element in the application screen
    This checkpoint causes test playback to wait for the application to come up. The checkpoint defaults (wait for enabled true, and wait up to 10 seconds) are usually fine for LAN testing or you can increase the timeout value.

Create checkpoints in this way to wait for some action to complete before taking another action or verifying some UI change from time to time during recording. This synchronization is necessary after server-side action; after client-side action you can do this or just add a 1-second wait. To add a 1-second wait, select Insert > Step > Step Generator > Functions > All > Wait, and set the argument to 1. Or switch to Expert View and enter the line Wait 1.

Click on the desktop pane so the NDesktop object get recorded.

Go through your application clicking buttons, dragging components, and typing text; whatever you want played back.

Checking the Return Value of any Method on a Nexaweb Component

At each point where you want to call a method on a component and check its return value: 

  1. Select Insert > Step > Loop Statement > do.. while.
  2. Change the while condition from False to notEqual(tv, "expected")' , where expected is the expected return value.
  3. Insert > Step > Step Generator > Category=Test Objects. Where object = your object (see Finding a Nexaweb Component As An Object ), Run-Time methods, method = your method from the dropdown; assign the return value to variable tv.
  4. Move your test cursor outside the loop so subsequent recording steps aren't in the loop.

Checking the Text of Texty Nexaweb Components

For the special case of calling getText() from a text component (textField, textArea), once per component:
select Insert >Step > Step Generator > Category=Test Objects. Where object = your object (see Finding a Nexaweb Component As An Object ).

If you do not see your object as a choice in the list of Test Objects under test presented:
-Click the hand icon
-Click the object under test in the application
-Select "Object" from Test methods
-Save value as a variable such as "ob1".
- In Expert View, insert Set at the beginning of the ob1=... line
- For each test on this component, enter a line such as checkObjectText ob1, "expected text"

Finding a Nexaweb Component As An Object

For a standard checkpoint on a Nexaweb component, or to check the value of one as in Checking the Return Value of any Method on a Nexaweb Component  and Checking the Text of Texty Nexaweb Components, you will need to select it in QTP.

In these step generator cases, if your object does not appear in the Test Objects dropdown list: click the Select Object button to the right of the dropdown and click the hand at the bottom of the dialog that appears. Your application appears so that you can click the Nexaweb component you wish to select. (From Standard Checkpoint you should come directly to this point.) Because your click lands in several nested components, you'll be presented with the list of possible objects of which you may often want the innermost. QTP identifies the objects by their java classnames. Thereore QTP lists:

  • a button as an NButton 
  • a textField as an NTextField
  • a textArea as an NRichLabel inside an NViewport inside an NScrollPane
  • a cell as an NTextField
  • a comboBox as an NButton and NTextField within an NCombobox; its listBox as an NTreeTable within an NPopup
  • radioButton and checkBox as an NToggleButton

Checkpointing DOM and ClientEvents

This method requires using the desktop client. If you're using the desktop client, and you pass -logFile log.xml (or another filename) to it on the command line, you can checkpoint the UI Dom at any point. At any point during recording that you wish to create such a checkpoint, type F9 anywhere in the application. Then from QTP, select Insert > Checkpoint > XML Checkpoint (File) and select the full file path, for example, C:\Nexa\log.xml. A display of current UI DOM elements appears. Check the elements you want checked. (Suggestion: Click the check all button above the XML display, then unselect buttons, which tend to have different styles depending on if they're currently clicked or recently clicked.) 

Stopping Recording

When you finish recording, close the browser or the desktop client's application window, and click Stop in QTP.

After Recording 

Follow these steps:

  1. Remove any clicks and types you recorded by mistake.
  2. Change to Expert View
    Recorded objects appear as NDesktopPane, NButton, NTextField, NRichLabel and so forth (NRichLabel represents textArea and textView as well as label.)
  3. Insert Set at the beginning of each obut = ... line you created.
  4. Correct any .PressKey events recorded incorrectly by QTP.
    For instance, QTP records main-keyboard alpha characters as capitals regardless of shift state, and numeric-keypad numerals as letters.
    If you set quick-test-pro-record-fix in nexaweb-client.xml, Nexaweb does most of the fixing for you, except for characters p through z, which you still need to fix up.
    You may correct these by replacing a sequence of .PressKey( char ) with a single .Type( String ). 
  5. Fix key modifier recording bugs. For instance:
    - Shift-Tab recording omits the shift, so change ...<object>.PressKey " " to ...<object>.PressKey " ", micShift.
    - Recording Ctrl-Shift-Left results in: ...<object>.PressKey "micShift + micLeft",micCtrl which you probably want to change to ...<object>.PressKey micLeft, micCtrlShift; however, playback of this may not work well, so do what works ...<object>.PressKey micShift + micLeft, micCtrl .
    - Shift-1 exclamation mark recording omitted the Shift: ...<object>.PressKey "1" so change it to ...<object>.PressKey "1", micShift or if that doesn't work,  Ctrl-Shift-$#@% it and ...<object>.PressKey "!" .

Playback

 To playback, in Keyword View, position cursor on top line, and click Run.

NexaQtpLib (for versions before 4.2.2+)

Use the following Nexaweb Test Script Libary to checkpoint the text of texty components:

  • (One time per test) Select Test / Settings / Resources and add the text of NexaQtpLib as "Associated Library File".
  • (One time per component):
    -Select Insert > Step > Step Generator > Category=Test Objects,
    object=your object (textField)
    -Select Object from Test methods, and save value with a distinct name such as ob1.
    -In Expert View, insert Set at beginning of this step.
  • (Each text check)  In Expert View, append line checkObjectText ob1, expected text

 

CR = chr(13)
LF = chr(10)
TAB = chr(9)
tv = "UNOVERWRITTEN"
DEFAULTTIMEOUT = 9 'seconds, override with "timeout=N" prior to do-while loop
timeout = DEFAULTTIMEOUT

Function notThereTM( val, trimFirst )
 If trimFirst Then
    tvt = Trim( tv )
 Else
 tvt = tv
 End If
 notThereTM = tvt <> val
 If notThereTM Then
  timeout = timeout - 1
  If timeout <= 0 Then
   timeout = DEFAULTTIMEOUT
   Reporter.ReportEvent micFail, "notThere value timeout", "expected='" + val + "', actual='" + tvt + "' ." +cStr( trimFirst )
   notThereTM = false
  Else
   Wait 1
  End If
 Else
 timeout = DEFAULTTIMEOUT
 Reporter.ReportEvent micPass, "notThere pass", "found val='" + tvt + "' ."
 End If
End Function

Function notThere( val )
 notThere = notThereTM( val, false )
End Function

Function notEqual( nowVal, checkVal )
 tv = nowVal
 notEqual = notThereTM( checkVal, false )
End Function

Function checkObjectText( obj, val )
 Do
  tv = obj.getText 
 Loop While notThereTM( val, false )
End Function

Function checkTrimmedObjectText( obj, val ) ' QTP's VB' impl Trim() is buggy; otherwise this is a fine idea
 Do
  tv = obj.getText
 Loop While notThereTM( val, true )
End Function