Custom Object Map Sanity Checks

Last edited on

Synopsis

Ignorance or negligence may cause test developers to add "problematic" object names to the test scripts. For example:

With the script based object map introduced in Squish 6.3 it has become very easy to inspect the object names (real names) within test script code itself, to perform any kind of checks on them before "increasing" the damage (of using the problematic object names in more and more script code).

The following example implementation checks for the use of "occurrence" properties in object names, as well as for top level object names which have not been "whitelisted" explicitly, and reports each occurrence in the test results, along with a few tips on how the user should proceed.

In this particular case the test script execution is also aborted, to force the user to act on this, rather than ignore the problem.

In case of Python, the checks are being performed upon importing the names.py module, which contains the object names by default. (However, the checks can be added to any other module, of course.)

Example Sanity Check Report

The Test Results view after execution of the test case, while having problematic object names in names.py:

The details for the object names failing the "occurrence" sanity check:

The details for the object names failing the "only expected top levels" sanity check:

Python

Adding the object map sanity check example implementation to an existing or new test suite is very easy, as shown below.

Once added, one needs to go through the reported problems and resolve them as desired.

Prerequisites:

Example names.py with added call to sanity check module:

# encoding: UTF-8

from objectmaphelper import *


### LINES BELOW ADDED FOR OBJECT MAP SANITY CHECK

import sys
import object_map_sanity_check


def sanity_check():
    # The top level object names which are known and considered
    # accepted; customize as required (!):
    #
    top_levels_whitelist = ["address_Book_MainWindow"]


    # The object names that are known to contain "occurrence" and
    # which are considered acceptable; customize as required (!):
    #
    occurrence_whitelist = ["address_Book_Add_Dialog"]


    # Use...
    #
    #  raise_errors=False
    #
    # ...below if you do not want the failing sanity checks to
    # abort the script execution:
    #
    object_map_sanity_check.perform_sanity_checks(
        sys.modules[__name__],
        top_levels_whitelist,
        occurrence_whitelist,
        raise_errors=False)


sanity_check()

### LINES ABOVE ADDED FOR OBJECT MAP SANITY CHECK


# Here follow the object names that were already present
# in this example names.py file:

address_Book_MainWindow = {"type": "MainWindow", "unnamed": 1, "visible": 1, "windowTitle": "Address Book"}

address_Book_Unnamed_MainWindow = {"type": "MainWindow", "unnamed": 1, "visible": 1, "windowTitle": "Address Book - Unnamed"}

address_Book_Add_Dialog = {"type": "Dialog", "occurrence": 1, "unnamed": 1, "visible": 1, "windowTitle": "Address Book - Add"}

#...
names.py