Saving screenshot of an object on the local computer

Last edited on


Screenshots of objects can be taken with the grabWidget() functions (grabWidget() (Qt), grabWidget() (Tk), grabWidget() (Java), grabWidget() (Web), grabWidget() (Windows)).

The resulting images can be stored on the computer where the squishserver is running or on a remote machine.

To copy the file to the computer where squishrunner is executing testData.get() can be used:

import os
import os.path
import sys

def main():
    # Register AUT with squishserver:
    aut = "addressbook"
    path = os.path.join(os.environ["SQUISH_PREFIX"], "examples", "qt", "addressbook")
    registerAUT(aut, path)

    save_screenshot({"type": "QMenuBar"}, "qmenubar.png")

def save_screenshot(obj_name, filename):
    widget = waitForObject(obj_name)
    # Create remote screenshot of the widget:
    img = grabWidget(widget), "PNG")

    # Copy remote file to computer that is executing
    # this script/squishrunner:

def registerAUT(aut, path, squishserver_host=None, squishserver_port=None):
    s = '"' + os.environ["SQUISH_PREFIX"] + '/bin/squishrunner"'
    if squishserver_host is not None:
        s += ' --host ' + squishserver_host
    if squishserver_port is not None:
        s += ' port=' + str(squishserver_port)
    s += ' --config addAUT "' + aut + '" "' + path + '"'
    if sys.platform == "win32" and s.endswith('"'):
        s = '"' + s
    test.log("Executing: " + s)

Related information

Creating and comparing screenshots at runtime