|Optional Step in UFT/QTP|
The below post will cover Optional Step in UFT,optional step in uft syntax,syntax for adding optional step in uft,How to add optional step in UFT?,Optional step a new way of coding.
Optional Step in UFT/QTP:
Consider a situation where a statement is not that much important to execute a test.But for QTP if that statement is not get executed might give an error and stop execution.
I can well remember one line of a QTP workshop where the trainer was explaining one scenario..
he needed to execute 1000 time a test case.He divided the the execution in 10 different machine which will execute 100 times each.He saw everything started fine and then he left for the day.
When came back next day morning and collecting the results he saw (to his bad luck) 8 machines got an error message on file download extra warning which was recorded initially. During execution it never appear.
Consider the trainer’s problem.He needed to start the execution from where they got stopped.
We were discussing this problem ,when my friend(Dadu) suggested one solution…Well Dadu is a great QTPian.He created a Hydrid framework.As per him ,we can add few extra lines to mitigate this risk.
The construction can be…
if Browser("XYZ").Page("ABC").WebButton("PQR").exists(3) then Browser("XYZ").Page("ABC").WebButton("PQR").click end if
The construction is very straight forward…if that button exist in the application then it will click else it will continue to execute.
But little we knew that we were going to face different kind of problem.
Well let me explain..There might be scenarios where
1. The developper has changed the object name in the test but the OR (Object Repository) is having the same old name)
2. The Developper has added/readded one object but the OR is not updated with this updated object.
Then this simple non value add line can stop your execution.Well Dadu could not answare this question.
Yes …we were looking for this solution…might be you all at this stage are looking for a solution …may be blaming HP for not implementing such scenarios like us…
The reply from HP is Optional Step…
If QuickTest cannot find an object designated as optional while running a test, it bypasses the step, and continues the run. By default, QuickTest automatically marks steps that open certain dialog boxes as optional. You can manually designate additional steps as optional.
It is applicable for the below written dialog boxes..
- Dialog Box Titlebar
- Any other Dialog Boxes
- File Download
- Internet Explorer
- Enter Network Password
- Security Alert
- Security Information
- Security Warning
- Username and Password Required
Setting Optional Steps
When recording a test, the application you are testing may prompt you to enter a user name and password in a login window. When you run the test, however, the application does not prompt you to enter your user name and password, because it has retained the information that was previously entered. In this case, the steps that were recorded for entering the login information are not required and should, therefore, be marked optional.When running a test, if a step in an optional dialog box does not open, QuickTest bypasses this step and continues to run the test. When the run session ends, a message is displayed for the step that failed to open the dialog box, but the step does not cause the test to fail.
To set an optional step in the Keyword View, right-click a step and choose Optional Step. The Optional Step icon is added next to the selected step.Note: Note: You can also add an optional step in the Expert View by adding OptionalStep to the beginning of the VBScript statement. For example:
The code looks like:
The part of it is ….Any other step can also converted to OptionalStep which can be avoided during execution.
So, Guys make any doubtful steps to Optional Step which will pretend as On Error Resume next.
More about Optional Steps:
An optional step is a step that is not necessarily required to successfully complete a run session. During a run session, if a step in an optional dialog box does not open, QuickTest bypasses this step and continues
to run the test. When the run session ends, a message is displayed for the step that failed to open the dialog box, but the step does not cause the run to fail.