Running another test

Sequence commands

These commands allows you to run other tests.

This helps you to create modular tests that can be easily reused and swapped out.

List of commands

TEST.run

Runs another test.

WARNING!
All tests run in the same scope. This means that variables with the same name in different tests will override each other.

Usage

TEST.run(path)

Parameters

ParameterTypeRemarks
pathstringPath to the test to run

Example(s)

Basic example using absolute path

Let's take this project with this structure for example.

|-- login
   |-- login_as_buyer
   |-- login_as_merchant
   |-- ...
|-- change_password

The contents of login/login_as_buyer is:

I.goTo("/login");
I.fill("username", "john");
I.fill("password", "supersecretpassword");
I.click("Login");

We can reuse login/login_as_buyer in a another test using the TEST.run command like this:

I.goTo('http://mystore.com');
TEST.run('login/login_as_buyer');

Which will result in a test like this when it is executed:

I.goTo('http://mystore.com');
I.goTo("/login");
I.fill("username", "john");
I.fill("password", "supersecretpassword");
I.click("Login");

Using TEST.run with relative paths

We can specify tests to run relative to the current test file.

Let's take this project with this structure for example.

|-- login
|-- order
   |-- create_and_view_order
   |-- create_order
   |-- view_order

From test order/create_and_view_order test, we can reference tests with relative paths like this:

TEST.run("../login") // use "../" to reference the parent directory
TEST.run("./create_order") // use "./" to referece the current directory
TEST.run("./view_order")


TEST.runOnce

It is a varient of TEST.run that runs another file, but only ONCE. If TEST.run is called on the same file again, it will not be ran.

Usage

TEST.runOnce(path)

Parameters

ParameterTypeRemarks
pathstringPath to the test to run

Example

TEST.runOnce("file/to/include/once") 
TEST.runOnce("file/to/include/once") 
TEST.runOnce("file/to/include/once") 

The script "file/to/include/once" is only executed ONCE in this scenario. This is useful for loading certain common setup scripts, in a more efficent manner.

Last Updated: