Optional Steps in UFTAneejian · May 27, 2015 · 2 mins read.
While automating with UFT, we face scenarios where a step is not necessarily required to complete a run session successfully.
Consider a scenario where you add login steps to your code because the application you are testing prompts to enter a username and password in a login window. Consider also that this application remembers user login details so that you do not need to log in every time you open the application.
During a run session, the application does not prompt you to enter your user name and password because it retained the information previously entered. In this case, the steps that you added for entering the login information are not required. We should mark these steps optional.
Once these steps are marked optional, during the subsequent run sessions, if the object of an optional step does not exist in the application, UFT bypasses this step and continues to run the test or component. At the end of the run session, UFT displays a message for the optional step, which it did not execute. Nevertheless, the step does not cause the run to fail.
However, run fails if UFT cannot find the object from the optional step in the object repository during a run session. This can happen due to object name modification in the test or component but not in the object repository, or if the object was removed from the object repository.
You can also manually designate steps as optional. For example, you can add conditional statements or use recovery scenarios to click a button automatically, press ENTER, or enter login information in a step.
During a recording session, UFT automatically marks steps that open certain dialog boxes as optional.
Default Optional Steps in QTP / UFT
By default, UFT considers steps that open the following dialog boxes or message boxes as optional steps:
|Dialog Box / Message Box Title Bar|
|Enter Network Password|
|Username and Password Required|
How to Set Optional Steps in UFT?
To set optional steps, do one of the following
In the Keyword View, right-click the step and select Optional Step. UFT adds Optional Step
In the Editor, add
OptionalStep to the beginning of the VBScript statement. For example: