Marionette JavaScript Tests

Marionette supports WebAPI tests written in JavaScript.  These tests must have a filename that begins with test_ and must have the extension .js.

Running the Tests

These tests are run using the Marionette Python testrunner; see Running Tests for more details.

Test Structure

All Marionette JavaScript WebAPI tests are asynchronous, and will not complete until the test calls finish().  When finish() is called, the framework collects information about all the assertions made during the test and sends it to the Marionette test driver, which will report the results.  For example:

// test logic (possibly asynchronous) goes here...
finish();

For examples, see the tests under dom/telephony/tests/marionette.

Test Flags

Marionette JavaScript WebAPI tests can utilize flags to direct Marionette to perform certain actions.

Flag Type Description
MARIONETTE_TIMEOUT integer The maximum number of seconds a test can wait for finish() to be called, before timing out.
MARIONETTE_CONTEXT string Either "content" or "chrome"; the context in which the test will be executed in.  Defaults to "content".

All flags are specified as JavaScript variable assignments inside the test file.  For example:

MARIONETTE_TIMEOUT = 30000; // 30s timeout
MARIONETTE_CONTEXT = "chrome"; // execute test in chrome context
// test logic (possibly asynchronous) goes here...
finish();

Test Functions

All JavaScript WebAPI tests have a number of functions available to them.

void is(value1, value2, message)
void isnot(value1, value2, message)
void ok(value, message)
void finish()
void log(message, level)
Array getLogs()
void waitFor(callback, test, timeout)
void runEmulatorCmd(cmd, callback)

is(value1, value2, message)

Asserts that two values are equivalent.  A failure of an assertion will cause the test to fail with the given message.

isnot(value1, value2, message)

Asserts that two values are not equivalent.  A failure of an assertion will cause the test to fail with the given message.

ok(value, message)

Asserts that a value is true.  A failure of an assertion will cause the test to fail with the given message.

finish()

Ends the test.

log(message, level)

Causes the specified message to be logged at the specified level.  Levels are arbitrary strings; defaults to "INFO".

getLogs()

Returns all the logs so far as an array, and clears the log.

waitFor(callback, test, timeout)

Repeatedly calls the function passed as the test parameter until that function returns true, then calls the callback.  If the test function does not return true within timeout ms, an exception is thrown.  The timeout parameter can be omitted, in which case a system default timeout is used.

runEmulatorCmd(cmd, callback)

Send the specified command string to the emulator's control port. The optional callback is invoked with an array containing the result lines of the command's output. Please refer to the Android Emulator documentation for the list of commands.

Document Tags and Contributors

Contributors to this page: jgriffin, Sheppy, fscholz, chrisdavidmills, mdas, philikon
Last updated by: chrisdavidmills,