Taking a parent object snapshot for better results analysis

Taking a parent object snapshot for better results analysis

From the Application Objects context menu, or from the Squish API, Squish can save an object snapshot. The snapshot contains detailed information about object state from the moment when the snapshot was taken. The snapshot lists object structure, all properties and their values, not only for the selected object but for its children as well.

Even with a complex logging approach, taking screenshots on failures, and self-explanatory naming convention, analyzing test results with failures might not be a simple task, especially if for some reason the object you are looking for couldn’t be found by Squish.

To make the analysis easier it’s possible to extend lookup functions (e.g. waitForObject) so in a case where they raise a LookupError, Squish tries to take a snapshot of the object’s parent. To achieve that we need to wrap the desired function with some additional code. Please note that the following example works only with Script-Based Object Map introduced in Squish6.4:

def waitForObjectAndSnap(funct):
    def wrapped(obj, timeout=20000):
        try:
            return funct(obj, timeout)
        except LookupError:
            if 'container' in obj.keys():
                parent = 'container'
            elif 'window' in obj.keys():
                parent = 'window'
            containerObj = waitForObject(obj[parent], 1000)
            saveObjectSnapshot(containerObj, 
                                os.path.join(squishinfo.resultDir, 
                                             str(containerObj.objectName)+"_.xml"))
            raise
    return wrapped
                
def wrapSquishFunction(function, wrappedFunctionGetter): 
    module = sys.modules["squish"]
    functionName = function.__name__
    if functionName in dir(module):
        wrappedFunction = wrappedFunctionGetter(getattr(module, functionName))
        setattr(module, functionName, wrappedFunction)
    else:
        raise RuntimeError("function %s not part of squish module" % functionName)
    if functionName in globals():
        globals()[functionName] = wrappedFunction

def main():
    startApplication("addressbook")

    wrapSquishFunction(waitForObject, waitForObjectAndSnap)
    waitForObject(names.my_object)

With this extension, if the waitForObject is not able to find an object, it tries to take a snapshot of a container or window of that object.

During the post-execution analysis, the snapshot file can be opened with a command line tool installed with the Squish package. The tool can be run with the following command:

<SQUISH_INSTALLATION_DIR>/bin/uibrowser.exe <path_to_a_snapshot_file>

 

0 Comments

Leave a reply

Your email address will not be published. Required fields are marked *

*