Creating screenshot verification points from test scripts

Last edited on

Example

Sometimes it can be useful to create verification points from inside a test script (i.e., at run time). The following examples show how to do that.

Python

import os
import os.path
import subprocess
import sys

from remotesystem import RemoteSystem

def main():
    startApplication('addressbook')

    widget = waitForObject({"type": "MainWindow"})
    vp_name = "svp"
    create_screenshot_vp(widget, vp_name)
    test.vp(vp_name)
 
def create_screenshot_vp(widget, vp_name):
    # Try to get a symbolic name for the widget:
    obj_name = objectMap.symbolicName(widget)
 
    # Create remote screenshot of the widget:
    img = grabWidget(widget)

    # Use only file name, do not specify folders, because
    # testData.get() would use the path on the remote as
    # well as the local system, and this may fail due to
    # file system differences or on mobile/embedded
    # devices (due to file system access restrictions):
    img_filename = 'cssvp_' + vp_name + '.png';

    img_filename2 = 'cssvp_' + vp_name + '.2.png';
    try:
        os.remove(img_filename)
    except:
        pass
    try:
        os.remove(img_filename2)
    except:
        pass
    img.save(img_filename)
 
    # Copy remote file to computer that is
    # executing this script/squishrunner:
    testData.get(img_filename)

    # Alternative, when started via startApplication(aut):
    #RemoteSystem().download(img_filename, img_filename2)
 
    # Create verification points folder:
    vp_dir = os.path.join(squishinfo.testCase, 'verificationPoints')
    if not os.path.exists(vp_dir):
        os.makedirs(vp_dir)
 
    vp_filename = os.path.join(vp_dir, vp_name)
 
    # Create verification point file:
    subprocess.call(
            [
                os.path.join(os.environ['SQUISH_PREFIX'], 'bin', 'convertvp'),
                "--tovp",
                vp_filename,
                img_filename2,
                obj_name
            ]
        )
test.py