An Alternative to Checkpoints

Reading the post over at QA Forums makes me realize how long this is in coming. Hopefully this kind of interruption won't happen much more. The good news is that we've learned much, and had most of our theories about how to implement QTP proven successful.

So, the question was about using QTP's built-in Checkpoints, and how to code these things manually. It must have been the second or third day of my experience with QTP that I went back to look at a checkpoint (because something in the AUT changed, yada yada), and I realized you couldn't do much without going through all the windows. There wasn't much flexibility. What was worse: you didn't really have a good, reliable way to tell a Checkpoint, "okay, Checkpoint, I don't mean it this time. Don't report anything if there's a failure."

We test a lot of our QTP code against client databases, where custom fields are littered everywhere, list boxes contain varied and dynamic entries, and nothing is very reliable. Furthermore, we want to be able to hand our QTP scripts off to our Professional Services organization so they can try the scripts out without failures coming from everywhere.

Point being, we needed the ability to dig really deep inside the point, and change the very nature of what a Checkpoint does. Now that we have it implemented, I can't believe Mercury never tried to implement something like this.

Our solution was based on JUnit (or whatever system JUnit based their practice on). When you run unit tests in JUnit, you perform an operation, then assert some expression against the results.

When the assertion is true, the test passes. When the assertion is false, the test fails.

Let's go through an example:

Use Case

  • Create a User with the user name of "foo" and password of "bar", assigned to the role of "Manager"
  • Ensure that the user has been created in the interface

This means, after I've created the user, I want to go in and "assert" several things about that user. In our code, one such assertion would look like this (there would be more abstraction and no hard-coded strings, but you get the idea):

Visual Basic:
  1. Set oUser = User.Create("foo", "bar", "Manager")
  2. assertStringEquals Browser("html id:=ApplicationName").Table.GetCellData(13, 2), _
  3.     "Manager", "Role Check", _
  4.     "Ensure the 'foo' user was properly assigned the 'Manager' role"

We have the following assert functions in our library (and we intend to write many more as the need arises):

Visual Basic:
  1. assertTrue( bExpression, sEvent, sDetails)
  2. assertNumEquals( iNum1, iNum2, sEvent, sDetails)
  3. assertStringContains( sSource, sPattern, sEvent, sDetails)
  4. assertStringEquals( sString1, sString2, sEvent, sDetails)
  5. assertWebListContains( ByRef oWebList, sString, sEvent, sDetails)
  6. assertEnabled( ByRef oWebObject, bEnabled, sEvent, sDetails)
  7. assertExists( ByRef oWebObject, bExists, sEvent, sDetails)

Those last two are attached to most of the test objects via RegisterUserFunc. The idea is that you only need to qualify the object, then instead of this code:

Visual Basic:
  1. If Browser("html id:=ApplicationName").[...].WebElement("html id:=foo").Exists Then
  2.      Reporter.ReportEvent micPass, "User Check", "Ensure existence of 'foo'"
  3. Else
  4.      Reporter.ReportEvent micFail, "User Check", "Ensure existence of 'foo'"
  5. End If

you have this:

Visual Basic:
  1. Browser("html id:=ApplicationName").[...].WebElement("html id:=foo").assertExists _
  2.      true, "User Check", "Ensure the user 'foo' exists"

There are some ins and outs and gotchas, and the messages you send to the reporter.reportevent don't tend to be as clear (i.e. you can't say "this failed"--the message is going to be the same whether it passes or fails), but that's about the same as you get with Checkpoints. Checkpoints by default do better reporting than these assertions, but if you put enough information into the reportevent call, you won't miss that too much. Especially with the flexibility and freedom you get in return.

Soon, we'll post the code within the assertions (and I mean it this time).

Tags: , ,

1 Comment for “An Alternative to Checkpoints”

  1. A2Ruth Says:

    I’m having trouble with checkpoints…but I’m working in a Windows environment. MS Dynamics GP. Identification numbers are created in one screen using a data table and are then searched (using the same data table), retrieved and assigned to records in another screen. It’s at this point that I want to insert a checkpoint. If the ID number *doesn’t* exist, the number most similar will be retrieved, so I want to verify that the ID number retrieved is identical to the ID number in the data table. (Yes, I’m a new user). Thanks for any help you can offer.

    Reply to A2Ruth

Leave a Reply