site
stats
By Anish Pillai Anish Pillai Posted under Advanced Concepts

Enhancing QTP Scripts: Display a Progress Bar during Static Wait

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 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.
Progress Bar used with Wait() function. The code for this Progress Bar is shown later in this post.

 

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.
Code –

‘Create an instance of the Windows Form
Set oWinForm = DotNetFactory.CreateInstance(

“System.Windows.Forms.Form”, “System.Windows.Forms”)
‘Create an instance of the Progress Bar control
Set oProgressBar = DotNetFactory.CreateInstance(

“System.Windows.Forms.ProgressBar”, “System.Windows.Forms”)

‘====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
oWinForm.Controls.Add oProgressBar
oWinForm.Show

‘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
oProgressBar.PerformStep()
Wait(1)
Next‘Close the progress bar
oWinForm.Close
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?

 

If you enjoyed this article, you can join our blog to get free email updates directly in your inbox.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • Neha

    This is very apprciable progress bar and I have used it in my QTP script .
    I have a question reagrding this-Suppose I ma having 10 Test cases which are being called from driver script and I am using this bar in driver script .Each time my test case is being called , I am doing perform step and oWinForm.Show to show progress to the user.
    But issue is that this progress bar is not updating at run time ,though it gets activate but show blank .
    It show complete bar once at the end of the script .
    Can you please provide solution so that it shows progress or get displayed at rum time.

    • Anish10110

      Can you share the code that you have used?

      • neha

        It is large driver script which we is being used in our framework , and want to use this progress bar feature in it.
        I will share the code as qfl file through mail,if possible can you please share your email id.

      • Neha

        Take this example:
        Dim Stepcount
        Stepcount=10
        Set oWinForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
        'Create an instance of the Progress Bar control
        Set oProgressBar = DotNetFactory.CreateInstance("System.Windows.Forms.ProgressBar", "System.Windows.Forms")
        oWinForm.Text = "Wait – 60 Seconds"
        oWinForm.Width = 300
        oWinForm.Height = 80
        oWinForm.MaximizeBox = False
        oWinForm.MinimizeBox = False'====Set the properties of the Progress Bar 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 =Stepcount 'Wait for 1 minute
        'oProgressBar.Value = 1
        'Set the step property to 1
        oProgressBar.Step = 1'Add the Progress Bar to the Form Window and display the controls
        oWinForm.Controls.Add oProgressBar
        oWinForm.Show

  • neha

    lets try this in a simple way ..you will see how bar is not being updated ::
    ‘Create an instance of the Windows Form
    Set oWinForm = DotNetFactory.CreateInstance(
    “System.Windows.Forms.Form”, “System.Windows.Forms”)
    ‘Create an instance of the Progress Bar control
    Set oProgressBar = DotNetFactory.CreateInstance(
    “System.Windows.Forms.ProgressBar”, “System.Windows.Forms”)

    ‘====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
    oWinForm.Controls.Add oProgressBar
    oWinForm.Show

    ‘Display the Progress Bar for the Wait duration
    For i = 1 to 10 ‘ For Wait Time of 1 minute
    ‘Advance the current position of the progress bar by the amount of the Step property
    oProgressBar.PerformStep()
    Wait(1)

    msgbox "running test case1"

    'now do perform step to increase progress bar after this step
    oProgressBar.PerformStep()
    oWinForm.Activate
    'now next step
    msgbox "second tc running"
    'now do perform step to increase progress bar after this step
    oProgressBar.PerformStep()
    oWinForm.Activate

  • neha

    for example take this script::

    ‘Create an instance of the Windows Form
    Set oWinForm = DotNetFactory.CreateInstance(
    “System.Windows.Forms.Form”, “System.Windows.Forms”)
    ‘Create an instance of the Progress Bar control
    Set oProgressBar = DotNetFactory.CreateInstance(
    “System.Windows.Forms.ProgressBar”, “System.Windows.Forms”)

    ‘====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
    oWinForm.Controls.Add oProgressBar
    oWinForm.Show

    ‘Display the Progress Bar for the Wait duration
    For i = 1 to 10 ‘ For Wait Time of 1 minute
    ‘Advance the current position of the progress bar by the amount of the Step property
    oProgressBar.PerformStep()
    oWinForm.Show
    Wait(1)
    Next‘Close the progress bar
    msgbox "Running Ist Test Case"
    oProgressBar.PerformStep()
    oWinForm.Activate

    msgbox "Running 2nd Test Case"
    oProgressBar.PerformStep()
    oWinForm.Activate

    oWinForm.Close

    You can check here after showing mesage box for test case, this will activate the progress bar ,but progress wont get updated at run time.,it will get updated at the end of the script.

  • Neha

    For i = 1 to 1 ' For Wait Time of 1 minute
    oProgressBar.PerformStep()
    Wait(1)
    Next
    msgbox "Running 1st Test case"
    oProgressBar.PerformStep()
    wait(2)
    oWinForm.Activate
    msgbox "Running 2nd Test Case"
    oProgressBar.PerformStep()
    wait(2)
    oWinForm.Activate
    oWinForm.close

    Here after displaying message box, Porgress bar is not being updated,it is updated at the end of the script.

  • neha

    Dim Stepcount
    Stepcount=10
    Set oWinForm = DotNetFactory.CreateInstance("System.Windows.Forms.Form", "System.Windows.Forms")
    Set oProgressBar = DotNetFactory.CreateInstance("System.Windows.Forms.ProgressBar", "System.Windows.Forms")
    oWinForm.Text = "Wait – 60 Seconds"
    oWinForm.Width = 300
    oWinForm.Height = 80
    oWinForm.MaximizeBox = False
    oWinForm.MinimizeBox = False
    oProgressBar.Top = 10
    oProgressBar.Left = 50
    oProgressBar.Width = 200
    oProgressBar.Height = 25
    oProgressBar.Minimum = 1
    oProgressBar.Maximum =StepCount

  • neha

    oProgressBar.Step = 1
    oWinForm.Controls.Add oProgressBar
    oWinForm.Show
    For i = 1 to 1 ' For Wait Time of 1 minute
    oProgressBar.PerformStep()
    Wait(1)
    Next
    msgbox "Running 1st tes Case"
    oProgressBar.PerformStep()
    wait(3)
    oWinForm.Activate
    msgbox "Running 2nd Test Case "
    oProgressBar.PerformStep()
    wait(2)
    oWinForm.Activate
    msgbox "Running 3rd Test Case"
    oProgressBar.PerformStep()
    wait(2)
    oWinForm.Activate
    oWinForm.close

    After message box ,progress bar is not updated at run time though at the end it is getting updated.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×