Recording a screen movie of the test execution

Last edited on

Synopsis

Recording a screen movie of the automation that is taking place can come in handy for debugging problems that occur while replaying test scripts.

Squish itself does not include functionality for screen recording yet, but it is generally possible to use external tools that satisfy the individual requirements.

The tool Open Broadcaster Software (OBS Studio, OBS) supports recording from various input sources, including the screen. In addition it has a command line interface, which makes it possible to integrate it with Squish. The rest of this article shows how to integrate screen recording via OBS into Squish test scripts.

Installing OBS

Please refer to Open Broadcaster Software for download and installing OBS.

As of version 19.0.3 OBS supports Linux, macOS and Windows.

Preparing OBS

After installing OBS it needs to be started to perform the initial configuration.

After startup, OBS looks similar to this:

Using OBS from Squish test scripts

Python

(See Executing external applications for starting external processes from test scripts.)

Requirements:

import os.path
import subprocess
import sys


# Adjust these as required:
movies_folder = os.path.expanduser("~")
if sys.platform == "win32":
    movies_folder = os.path.expanduser("~/Videos")

movies_snapshot = []


def main():
    startApplication("addressbook")
    snooze(10)
    return


def init():
    global movies_snapshot
    movies_snapshot = movies_list()

    test.log("Starting screen recording...")
    start_screen_recording()
    test.log("Starting screen recording...done.")


def cleanup():
    test.log("Stopping screen recording...")
    stop_screen_recording()
    test.log("Stopping screen recording...done.")

    test.log("Waiting for new movie file...")
    global movies_snapshot
    new_found = False
    for i in range(20):
        current_movies = movies_list()
        new_movies = []
        for fn in current_movies:
            if fn not in movies_snapshot:
                new_found = True
                test.log("New movie: %s" % fn)
        if new_found:
            break
        snooze(1)


def start_screen_recording():
    args = [
            python_binary(),
            os.path.join(squishinfo.testCase, "..", "obs_wrapper.py"),
            "--startrecording"
        ]
    p = subprocess.Popen(args=args)
    p.communicate()

    # The actual start of the recording takes a few
    # seconds, so wait a bit: 
    snooze(5)


def stop_screen_recording():
    args = [
            python_binary(),
            os.path.join(squishinfo.testCase, "..", "obs_wrapper.py"),
            "--stoprecording"
        ]
    p = subprocess.Popen(args=args)
    p.communicate()
    snooze(5)


def movies_list():
    global movies_folder
    list = os.listdir(movies_folder)
    movies = []
    for fn in list:
        if fn.endswith(".flv"):
            movies.append(fn)
    return movies


def python_binary():
    python_binary = os.path.join(os.getenv("SQUISH_PREFIX"), "python", "bin", "python"),
    if sys.platform == "win32":
        python_binary = os.path.join(os.getenv("SQUISH_PREFIX"), "python", "python")
    return python_binary

Additional Information