January 3, 2013

Using Repository Variables as Expected Values

Helix ALM

DEWEY DEFEATS TRUMAN!

MEN WALK ON MOON!

BAT BOY LEADS COPS ON Three STATE CHASE!

Headlines are constantly changing—regardless of whether they are in printed newspapers or virtual on the web. If you are using QA Wizard Pro to test an application that is changing, you may find yourself re-recording scripts or populating the application repository to ensure the newest controls are captured. Instead of trying to keep up with the changes, consider using a repository variable as the expected value in the search criteria for a control, allowing you to specify the needed value at runtime. The value of the variable can be set in the script itself, or if you read in the values from a datasheet you can change the script behavior without changing the script or modifying the repository. There are many benefits to this, including better playback performance since there are fewer items to search through, and the ability to access items that have not explicitly been added to the repository. As an example, look at any online news site. As time goes by links to new articles are added and stale links are removed. If you record a script which checks that a particular link exists on the news site page, you would need to constantly record new scripts and update the repository. The script step:
    Window(“News Headlines”).HTMLLink(“DEWEY DEFEATS TRUMAN!”).CheckExists(False,””)
... would be replaced by a new step...
    Window(“News Headlines”).HTMLLink(“MEN WALK ON MOON!”).CheckExists(False,””)
... which would eventually be replaced by...
    Window(“News Headlines”).HTMLLink(“BAT BOY LEADS COPS ON 3 STATE CHASE!”).CheckExists(False,””)
... and so on. Assuming you know what the link text will be, you can record a script that checks for one link and modify it for reuse:
  • Create a repository variable LINKTEXT (refer to  “Using Repository Variables” in the QA Wizard Pro documentation for how to do this).
  • Modify the repository entry for one of the links in the recorded script as follows:

- Ensure that ‘Inner Text’ is the only property being used as search criteria.

- Replace the recorded ‘Inner Text’ expected value with the repository variable name. The variable name will need to have the percent sign prepended and appended (%LINKTEXT%).

- Rename the control so it does not reference the specific link (remember this name is for lookup purposes only), such as “Link”. You will be prompted to synchronize your scripts so that the control names are updated.

  • Add a step to the script that assigns a value to the LINKTEXT variable, somewhere before the step that interacts with the link. During playback, the script will search for a link with that ‘Inner Text’ value.
[caption id="attachment_12461" align="alignnone" width="611"] Control Properties for an HTMLink[/caption] To test the changing headlines in our example:
LINKTEXT=”DEWEY DEFEATS TRUMAN!”
Window(“News Headlines”).HTMLLink(“Link”).CheckExists(False,””)
LINKTEXT="MEN WALK ON MOON!"
Window(“News Headlines”).HTMLLink(“Link”).CheckExists(False,””)
LINKTEXT=”BAT BOY LEADS COPS ON 3 STATE CHASE!”
Window(“News Headlines”).HTMLLink(“Link”).CheckExists(False,””)
The script becomes even more efficient if you make it data-driven, and loop through and pull in values from a spreadsheet or database:
LINKTEXT=GetRowValue(File,”headline”)
Window(“News Headlines”).HTMLLink(“Link”).CheckExists(False,””)
There are many different ways this concept can be applied. By making similar changes to your scripts you can enjoy the benefit of spending less time on script maintenance and more time on testing.