Knowledgebase

Search:     Advanced search

Handling Known Exceptions

Article ID: 835  |  Last updated: 29 Dec, 2014

Exceptions are known events in an application that interrupt its expected operation. For example, a dialog box may open if a user does not enter a username or password before clicking the Login button. If the dialog box opens during script playback, the script fails unless it contains steps to handle this behavior.

You can handle known exceptions in scripts using the If statement with the WaitForExists statement.

To handle an exception in a script:

  1. Record a script that opens the exception. Update the window or control properties in the application repository if needed.
  2. Add a variable to the script that uses the value returned by the WaitForExists statement (True or False).
  3. Add an If statement to indicate how to handle the exception. The If condition should use the value returned by the WaitForExists statement (True or False).
  4. Add the steps to handle the exception in the statement.

WaitForExists statement

The WaitForExists statement returns True or False to indicate if a window or control is found during a specified number of milliseconds. Playback is paused until the window or control is found.

Syntax:

WaitForExists(WaitTime)

  • WaitTime—Time to wait (in milliseconds)

Example

A dialog box opens if you click the Login button on a web page before entering a username and password. If the dialog box opens as the script runs, you want to close it and continue running the script. The following steps explain how you can modify the script to handle the exception.

  1. Record a script that opens the dialog box and clicks the OK button to close it.
  2. Select the step that clicks the Login button.
  3. Choose Script > Add Statement.
  4. Select Assignment.
    • Enter LOGIN_ERROR as the Assignment Variable.
    • Select Expression and enter Window("EnterUserPassword").WaitForExists(5000). This tells QA Wizard Pro to wait five seconds for the dialog box (EnterUserPassword window) to open before continuing the script. The WaitForExists statement returns True if the window opens within five seconds and False if it does not open.
    • Click OK.
  5. Choose Script > Add Statement.
  6. Select If.
    • Enter LOGIN_ERROR = "True" as the Condition. This tells QA Wizard Pro to only run the steps in the If statement block if the value returned by the WaitForExists statement is True. Otherwise, the script continues with the first step outside of the If statement block.
    • Click OK.
  7. Move the step that clicks the OK button in the dialog box inside the If statement block. This step only runs if the value returned by the WaitForExists statement is True. 
Article ID: 835  |   Last updated: 29 Dec, 2014
Tags
exceptions If statement WaitForExists

Prev   Next
Text Data Not Imported from Excel Files to Datasheets     Scripts Without a SetContext Statement Do Not Synchronize