录制测试执行的屏幕电影

最后编辑了

概要

录制正在发生的自动化的屏幕电影可以派上可以在重播测试脚本时进行调试的问题。

SQUISH本身不包括屏幕录制功能,但通常可以使用满足各个要求的外部工具。

工具 开放广播软件 (obs工作室, obs.)支持从各种输入源进行录制,包括屏幕。此外,它有一个命令行界面,这使得它可以将其与蜂鸣器集成。本文其余部分显示了如何集成屏幕录制通过 obs. 进入粗糙的测试脚本。

安装 obs.

请参阅 开放广播软件 用于下载和安装 obs..

截至19.0.3版 obs. 支持Linux,MacOS和Windows。

准备 obs.

安装后 obs. 它需要开始执行初始配置。

启动后, obs. 看起来类似于:

使用 obs. 从鳞上测测试脚本

Python

(看 执行外部应用程序 用于从测试脚本启动外部进程。)

要求:

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

附加信息

$ obs --help
--help, -h: Get list of available commands.

--startstreaming: Automatically start streaming.
--startrecording: Automatically start recording.
--startreplaybuffer: Start replay buffer.

--collection <string>: Use specific scene collection.
--profile <string>: Use specific profile.
--scene <string>: Start with specific scene.

--studio-mode: Enable studio mode.
--minimize-to-tray: Minimize to system tray.
--portable, -p: Use portable mode.

--verbose: Make log more verbose.
--always-on-top: Start in 'always on top' mode.

--unfiltered_log: Make log unfiltered.

--allow-opengl: Allow OpenGL on Windows.

--version, -V: Get current version.