Semi automatic testing

Last edited on



Overview

The following solution is based on the open source project easygui .

Installation

Download and save these two files in your test suite directory:

Using the choicebox.py script from JavaScript

To use the above Python script from inside your test script use something like the choicebox function in this example:

function main() {
    var c = choicebox("Message", "Title", ["Choice 1", "Choice 2"]);
    test.log(c);
}

function choicebox(msg, title, choicesArray) {
    var cmd = 'python "' + squishinfo.testCase + '/../choicebox.py"';
    cmd += ' "' + msg + '"';
    cmd += ' "' + title + '"';
    for (var i = 0; i < choicesArray.length; i++) {
        cmd += ' "' + choicesArray[i] + '"';
    }

    return OS.capture(cmd);
}
test.js

Using the choicebox.py script from Python

To use the above Python script from inside your test script use something like the choicebox function in this example:

# -*- coding: utf-8 -*-

import subprocess


def main():
    c = choicebox("Message", "Title", ["Choice 1", "Choice 2"])
    test.log(c)


def choicebox(msg, title, choices_array):
    cmd = ["python"]
    cmd.append(squishinfo.testCase + "/../choicebox.py")
    cmd.append(msg)
    cmd.append(title)
    for c in choices_array:
        cmd.append(c)

    return os_capture(cmd)


def os_capture(cmd):
    res = subprocess.Popen(
            args=cmd,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT
        ).communicate()
    return res[0].decode("utf8)
test.py