QTP/UFT tutorial for beginners- synchronization between your application and QTP/UFT Part 2

Hello! In this first part of the synchronization, we practiced setting conditions to synchronize our script with our application. Now we want to go a step further, and set some pass fail events for those conditions. We will continue with the practice object I created below.

Synchronize Here

Last time, we used this condition to wait for this object to load:

If Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Exist(120) Then
    Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Click
End If

For every act we perform in automation, we would like a pass/fail condition. We do this for two reasons.

  1. The test results that print our detailed steps, can be used to debug and enhance our scripts
  2. The test results are a helpful tool for non technical individuals to see the automation test coverage.

We will user Reporter.ReportEvent method to let us know if our script is passing or failing. In our code above, I added two conditions:

If Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Exist(120) Then
Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here").Click
Reporter.ReportEvent micPass, "Synchronize Here", "Link exists on the web post"
Else
Reporter.ReportEvent micFail, "Synchronize Here", "Link does not exist on the web post"
End If

In the code above, the condition dictates that if the Synchronize Here link exists, then click on it and show a pass on the rerpot. If the link does not appear on the page, then show a fail on the report. "Synchronize Here" is the step name that failed, and "Link does not exist on the web post" is the detailed message of why it failed.

Run the code above and you should see a passing report.

 

Cool right?

Now we can see what happens if our object is not found on the web post. Below, I changed the innertext to an incorrect value.

If Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here1").Exist(120) Then
     Browser("Index:=0").Page("title:=.*").link("name:=Synchronize Here1").Click
     Reporter.ReportEvent micPass, "Synchronize Here", "Link exists on the web post"
     Else
     Reporter.ReportEvent micFail, "Synchronize Here", "Link does not exist on the web post"
 End If

Run the code above and you should see a fail in the report.

Cool right? This is how you use conditioning and pass/fail conditions within your script. Please leave comments and feedback below.

Pin It on Pinterest

Clef two-factor authentication