Micro Focus QTP (UFT) Forums
Repeating If loop - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Repeating If loop (/Thread-Repeating-If-loop)



Repeating If loop - mv8167 - 06-30-2011

The loop below checks a date range, if no data is returned, a new date is used. If the 1st date fails, I check another date.

How can I better check if no data is found without using an If statement within an If statement?

Do loop?

My code:

Code:
If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").Exist(5) Then
        'No data found for ACCT1 in ENV
        Reporter.ReportEvent micFail,"No Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has no Data."
        'Try secondary End Date (eDate2)
        Browser("Wisdom").Page("Wisdom IA").Frame("parent").Image("button_newsearch").Click
        Browser("Fax Request").Page("Preferences").WebEdit("EndDate").Set eDate2 '=  "03/25/2011"
        Browser("Fax Request").Page("Preferences").WebElement("SearchPrefPage").Click
        If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").Exist(5) Then
            Reporter.ReportEvent micFail,"No Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has no Data."
            ExitTest
        Else
        'data found for ACCT1 in ENV
        Reporter.ReportEvent micPass, "Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has Data."
        End If
Else
        'data found for ACCT1 in ENV
        Reporter.ReportEvent micPass, "Data found for Row:  " & DataTable.GlobalSheet.GetCurrentRow, " The Account Number: " & Datatable("ACCT1", dtGlobalSheet) & " in the ENV: " & Datatable("ENV", dtGlobalSheet) & " - has Data."
End If



RE: Repeating If loop - parminderdhiman84 - 06-30-2011

Lorena,

Its not clear what you want to achieve. Just add some screenshots and details.

Regards,
Parminder


RE: Repeating If loop - mv8167 - 06-30-2011

Screenshots wont help, this is more of a coding issue.

Let me try and better explain.

I search on a StartDate to an EndDate. If I get no data returned to my screen, an error message indicates "No Results Found".

If no results are found, I want to notify that the first date failed and thus try a second date (by taking today's date minus 1 day). If the second try fails, I know to exit from this test only.

Beter?

;-)?


RE: Repeating If loop - parminderdhiman84 - 06-30-2011

Lorena,

Your code seems right. Does that return any error? If not then OK to use that code. Maybe somebody else make it perform better Smile ?

Regards,
Parminder


RE: Repeating If loop - mv8167 - 07-01-2011

Thx Parminder,

I do not get an error, but ...

First,
I changed my code. The first If stement (when no data is retevied) works fine. But the second If statement Still goes to fail even though data is present on the page. I get a warning stating that

Warning or Fail
"If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then" is not found.

My code gives me a warning or fails when WebElement("No Results Found") is not found. My goal is to check if the WebElement("No Results Found") is displayed, if it is then use today's date minus one day. Then check again if WebElement("No Results Found") is visible.

But if WebElement("No Results Found") is not visible (as data is present), my code still marks as Fail.

How can I better check for the message ("No Results Found")? and continue if not found.

Second,
My date code:
TodayDate = DateAdd("d",-1,Now())
eDate = FormatDateTime(TodayDate,2)

returns 7/1/2011, but this fails as the program only alows mm/dd/yyyy (so, Im need 07/01/2011) or I get an error message.

My code:

Code:
CurrentRow =  DataTable.GlobalSheet.GetCurrentRow
ACCT = Datatable("ACCT1", dtGlobalSheet)
ENV = Datatable("ENV", dtGlobalSheet)

If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then
      'No data found for EndDate in ENV
       eDate = DateAdd("d",-1,Now())
      eDate = FormatDateTime(eDate,2)
        'Try secondary End Date (Today minus 1 day)
      Browser("Wisdom").Page("Wisdom IA").Frame("parent").Image("button_newsearch").Click
      Browser("Fax Request").Page("Preferences").WebEdit("EndDate").Set eDate
      Browser("Fax Request").Page("Preferences").WebElement("SearchPrefPage").Click
      If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then
         Reporter.ReportEvent micFail,"No Data found for Row:  " & CurrentRow & " The Account Number: " & ACCT & " in the ENV: " & ENV & " - has no Data."
         ExitTest
      Else
      'data found for EndDate in ENV
      Reporter.ReportEvent micPass, "Data found for Row:  " & CurrentRow & " The Account Number: " & ACCT & " in the ENV: " & ENV & " - has Data."
      End If
Else
      'data found for EndDate in ENV
      Reporter.ReportEvent micPass, "Data found for Row:  " & CurrentRow & " The Account Number: " & ACCT & " in the ENV: " & ENV & " - has Data."
End If



RE: Repeating If loop - rajpes - 07-04-2011

Quote: Warning or Fail
"If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").GetROProperty("visible") = True Then" is not found.

My code gives me a warning or fails when WebElement("No Results Found") is not found. My goal is to check if the WebElement("No Results Found") is displayed,
You can not use GetRoProperty for an object which doesn't exist(in your case it may/'nt exist)
so use .Exist method again as you used in first line


If Browser("Wisdom").Page("Wisdom IA").Frame("parent").WebElement("No Results Found").Exist(5) Then

And to make your code look better, use a function to test data availability by just passing date parameter and get the returned value as boolean found or not found

By the way "If" is not a loop, it's a conditional statement!


RE: Repeating If loop - mv8167 - 07-06-2011

Thx, I did this last week. I just used todays date minus 1, then I checked with Exist but only one time. If no data exists then I fail and move on.

thx for the help ;-)