By Anish Pillai Advanced ConceptsPosted under
Enhancing QTP Scripts: Display a Progress Bar during Static Wait
0 Flares 0 Flares ×
Numerous times we would have come across the situation where we need to use the Wait() function in our scripts. Consider a scenario where user has to script for auto timeout functionality of the application. i.e. the application under test (AUT) should log out automatically if its left idle for some fixed duration of time. In such situations, the automation tester can use the Wait() function specifying the wait time.
Now what happens when this script is run as a part of a batch mode and the user is not aware which test case is currently being executed. Or the user executing the test case is not aware of the wait duration. In such situations, the user would not be able to figure out whether the script is running fine or whether it got stuck somewhere. For such situations it would be a great idea to have some sort of popup displayed which indicates to the users that the script is indeed working fine. A ‘Progress Bar’ is best suited for this situation as the advance in the progress bar would help the user figure out the remaining amount of time left. Let’s see how this works.
Steps to create a Progress Bar control in QTP
- Create a Windows Form.
- Create a Progress Bar control and add it in the Windows Form.
- Configure the Progress Bar for the ‘Wait’ duration.
To create a Windows Form, Progress Bar or any other windows control, QTP has provided DotNetFactory object. This DotNetFactory object enables the users to create an instance of a .Net object, and access all it properties & methods.
Lets see the code for displaying a progress bar for Wait() function execution.
|‘Create an instance of the Windows Form
Set oWinForm = DotNetFactory.CreateInstance(
‘Create an instance of the Progress Bar control
Set oProgressBar = DotNetFactory.CreateInstance(
‘====Specify size and other attributes for the Windows Form====
‘Set the title of the Form
oWinForm.Text = “Wait – 60 Seconds”
‘Set the size of the Windows Form
oWinForm.Width = 300
oWinForm.Height = 80
‘Set the MaximizeBox to false to remove the maximize box
oWinForm.MaximizeBox = False
‘Set the MinimizeBox to false to remove the minimize box
oWinForm.MinimizeBox = False‘====Set the properties of the Progress Bar control====
‘Set Progress Bar location wrt the Form Control
oProgressBar.Top = 10
oProgressBar.Left = 50
oProgressBar.Width = 200
oProgressBar.Height = 25‘Set the minimum value to 1
oProgressBar.Minimum = 1
‘Set the maximum value to the number of seconds to be waited
oProgressBar.Maximum = 60 ‘ Wait for 1 minute
‘Set the initial value of the ProgressBar
oProgressBar.Value = 1
‘Set the step property to 1
oProgressBar.Step = 1‘Add the Progress Bar to the Form Window and display the controls
‘Display the Progress Bar for the Wait duration
For i = 1 to 60 ‘ For Wait Time of 1 minute
‘Advance the current position of the progress bar by the amount of the Step property
Next‘Close the progress bar
In this example, we have included a progress bar control together with the Wait() function. Here, the position of the Progress Bar would advance with each step and by the end of the wait time, the progress bar would also have advanced till the end, giving the users a fairly good idea about the remaining wait time.In this same code, users can add other many other things such as a text label which can display the remaining amount of wait time left. This is just one example where the progress bar would come in handy. Can you think of any other situations where this control can be used?