Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Count the number of times the object appeared in the run
#1
Solved: 10 Years, 9 Months, 1 Week ago
Hi All,

I have a problem in QTP. I want to count the number of times a particular object is shown during my run. Here is the scenario:

I have 4 sets of data in Data Table, 3 of which would give me a pop-up window during a run. Now, I want to return the number of times that pop-up window was showed when I click Run. I want the result displayed in the Results window.

Please help! Thank you!

Yono
#2
Solved: 10 Years, 9 Months, 1 Week ago
How do you handle the Pop-up ? Please paste your code so that we can see what help we can extend.

Maybe you can extend a counter variable which will hold the number of clicks and then write it to the Reporter statement.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
#3
Solved: 10 Years, 9 Months, 1 Week ago
Hi,

As Basanth said you can use the Counter Variable. Below is a sample code from Flight Reservation Application, which gives the useage of Counter variable in Reporter Events.

Also, you can see the Screen Shot which gives the No. of Pop-Up's displayed for each Pop-Up Dialog's.

Code:
Dim a,k
a= DataTable.GetRowCount

For i=1 to a
    DataTable.SetCurrentRow(i)
    b=DataTable.Value("AgentName",dtGlobalSheet)
    c= DataTable.Value("Password",dtGlobalSheet)
    d= DataTable.Value("CorrectPassword",dtGlobalSheet)
    e= DataTable.Value("DateofFlight",dtGlobalSheet)
    f= DataTable.Value("FlyFrom",dtGlobalSheet)
    
    Dialog("Login").WinEdit("Agent Name:").Set b
    Dialog("Login").WinEdit("Password:").Set c
    Dialog("Login").WinButton("OK").Click
    
    If Dialog("Flight Reservations").Exist Then
        k=k+1
        Reporter.ReportEvent micPass, "Verify Flight Reservations Dialog","Flight Reservation Pop-Up dialog is displayed "&"-"&"No of Pop-Up's:" & k
    End If
    Dialog("Flight Reservations").WinButton("OK").Click

    Dialog("Login").WinEdit("Password:").Set d
    Dialog("Login").WinButton("OK").Click

    wait 5

    If Window("Flight Reservation").Exist Then
        Reporter.ReportEvent micPass,"Verify Flight Reservation dialog","Flight Reservation Dialog is displayed"
        Else
        Reporter.ReportEvent micFail,"Verify Flight Reservation dialog", "Flight Reservation Dialog is Not displayed"
    End If

    Window("Flight Reservation").ActiveX("MaskEdBox").Type e
    Window("Flight Reservation").WinComboBox("Fly From:").Select f

    If Window("Flight Reservation").Dialog("Flight Reservations").Exist  Then
        k=k+1
        Reporter.ReportEvent micPass,"Verify Flight Reservations dialog","Flight Reservation Pop-Up dialog is displayed "&"-"&"No of Pop-Up's:" &k
        
    End If
    Window("Flight Reservation").Dialog("Flight Reservations").WinButton("OK").Click

Next


Cheers,
Deepak.Bhandarkar


Attached Files Image(s)
   
#4
Solved: 10 Years, 9 Months, 1 Week ago
@qtpDeepak - Please wrap your code whenever you post.

The solution you have provided is not correct. This will always print 1 popup for the first reporter, 2 for the second one irrespective of how many times it comes up. The reason being, If is a conditional loop which will enter only once. Your counter will take iterate only once depending upon the previous k value. Morever your counter is not capturing multiple occurences of the same popup during the same instance.

Iteration counters are in the logical loop, for Next and While wend or if you require in the run instance then the occurences of the object needs to be counted and stored in the variable separately.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
#5
Solved: 10 Years, 9 Months, 1 Week ago
Yeah Basanth, You're right. My script is capturing the No of Times the Pop-up's appears. It is not taking into consideration the Similar Pop-Up Objects.

I will try to learn this part as well. Thanks for guiding me on this one.

Cheers,
Deepak.Bhandarkar
#6
Solved: 10 Years, 9 Months, 1 Week ago
Hi! Thanks for all your help, but Basanth is correct. The code only repeats the entire loop and iteration.

What I need to know is how can I show in the results that a particular window appeared nth times. Here goes the scenario.

I have an action that iterates 4 times when I run. This is because I have 4 sets of data. And for each iteration, a dialog box maybe displayed depending on the value inputted. I want to know how can I count the number of times that particular dialog box appeared in the run and display it (count) in the result. Below are some lines from the codes:

Code:
If  JavaWindow("WINDOW_NAME").JavaDialog("DATA").Exist Then
     Reporter.ReportEvent micDone, "Dialog box", "Dialog Box Appeared"
JavaWindow("WINDOW_NAME").JavaDialog("DATA").JavaButton("OK").Click
     counter = counter +1 'This is where I am trying to get the count but this variable resets to 0 every new iteration.
End If

Please advise.

Thank you!
Yono
#7
Solved: 10 Years, 9 Months, 1 Week ago
Yono -
You may want to store the counter variable value on to a cell in the datatable and for every iteration append it with the previous value. On your reporter pick the final value from the cell and write it on.

Does this logic help you ?
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
#8
Solved: 10 Years, 9 Months, 1 Week ago
Hi Basanth,

The logic looks fine, thank you. My problem now is how can I assign the variable to a cell. I'm really a newbie in QTP.

Thanks!
Yono
#9
Solved: 10 Years, 9 Months, 1 Week ago
Hi Yonobev,

Please create a new thread for your new query.
always make a habbit to put one query per thread.

Thread closed



Possibly Related Threads…
Thread Author Replies Views Last Post
  swfwindow object name getting changed after each run saniya 1 1,486 10-10-2018, 09:02 PM
Last Post: TheGlovner
  Web Object Unique ID Number zunebuggy 0 1,456 07-10-2017, 05:37 PM
Last Post: zunebuggy
  QTP not recogonising object during run time Lavanya N 2 3,536 10-28-2015, 12:46 PM
Last Post: vinod123
  VB Script to count number of links in a web page. Suma Parimal 4 24,756 07-01-2015, 12:59 PM
Last Post: govind
  General run error. Line (18): "Loop while Browser("Index:=0").Object.Busy" AshokReddy 3 4,792 12-20-2013, 01:44 PM
Last Post: sshukla12

Forum Jump:


Users browsing this thread: 1 Guest(s)