Interactive

In addition to the default batch mode for running tests, Testplan also allows tests and their environments to be run in an “interactive” mode. Currently only the backend HTTP (REST) API is implemented. The examples below show different ways you can connect to Testplan’s interactive API. Though powerful and flexible, API access is a feature suitable for more advanced users that are happy to build their own client. We are currently working on a web page front-end that will allow user-friendly control of tests and their environments - watch this space for updates soon!

Basic

Required files:

test_plan.py

#!/usr/bin/env python

import sys

from testplan import test_plan
from testplan.report.testing.styles import Style, StyleEnum

from my_tests.mtest import make_multitest


# Hard coding interactive mode usage.
@test_plan(
    name="MyPlan",
    interactive_port=0,
    stdout_style=Style(
        passing=StyleEnum.ASSERTION_DETAIL, failing=StyleEnum.ASSERTION_DETAIL
    ),
)
def main(plan):

    # Adding two multitests
    plan.add(make_multitest(idx="1"))
    plan.add(make_multitest(idx="2"))


if __name__ == "__main__":
    sys.exit(not main())


# INTERACTIVE MODE DEMO:
# ----------------------
#
# You can browse the API schema at either localhost or at the LAN address
# that's printed when running this testplan script. The API schema is
# interactive so you can test out the available functionality. In order to
# run a test, issue a PUT request with the test's status set to "running".

my_tests/mtest.py

from testplan.common.utils.context import context
from testplan.testing.multitest import MultiTest
from testplan.testing.multitest.driver.tcp import TCPServer, TCPClient

from my_tests.basic import BasicSuite
from my_tests.tcp import TCPSuite


def make_multitest(idx=""):
    def accept_connection(env):
        env.server.accept_connection()

    return MultiTest(
        name="Test{}".format(idx),
        suites=[BasicSuite(), TCPSuite()],
        environment=[
            TCPServer(name="server"),
            TCPClient(
                name="client",
                host=context("server", "{{host}}"),
                port=context("server", "{{port}}"),
            ),
        ],
        after_start=accept_connection,
    )