Assertions and Test subjects

Suitest lets you inspect different objects inside the application and provides flexible ways to create assertions about the object's properties. This is done with the use of different test subjects combined with chain modifiers.


List of assertions and test subjects:


application

application() defines an Application subject. Needs to be combined with hasExited.

/**
 * @returns {ChainablePromise.<void|boolean>}
 */
async function application() {}

// Check if application has exited
const ApplicationHasExited = await suitest.application().hasExited();

cookie() defines a Cookie subject.

/**
 * @param {string} name - cookie name
 * @returns {ChainablePromise.<void|boolean|string>}
 */
async function cookie(name) {}

const cookieValue = await suitest.cookie('cookieName');

With the extensive features of our Lite solution on some of the platforms, you can validate more details of cookies as well as check the 3rd party cookies. See more information.

element

element() defines a View element subject.

The element apiId can be found in the element repository.

/**
 * @param {string} apiId - Api ID of the element from Element Repository
 */
async function element(apiId) {}

/**
 * @param {string} [css] - CSS selector, e.g. ”#elementID > .child-element”
 * @param {string} [xpath] - XPath selector. Note that not all platforms support XPath
 * @param {number} [index] - which element should be taken when more then one match found
 * @param {string} [attributes] - select element by it's attributes
 * @param {string} [text] - select element by inner text
 * @param {string} [position] - select element by it's position
 * @param {string} [size] - select element by it's size
 * @param {string} [color] - select element by color
 * @param {boolean} [video] - select video element
 * @returns {ChainablePromise.<void|boolean|Object>}
 */
async function element({css, xpath, index, attributes, text, position, size, color, video}) {}

// Look up element by API ID in Element Repository
const elementProps = await suitest.element('ElementApiID');

// Look up element by complex selector. All keys are optional, but at least one must exist
const elementProps = await suitest.element({
    css: 'css selector',
    xpath: 'xpath selector',
    index: 1,
}).exists();

// registering a handle
const menuItemHandle = await suitest.element({
    css: '.menu-item'
}).handle();

// using the handle
await suitest.element({handle:menuItemHandle}).exists();

jsExpression

jsExpression() defines a JavaScript expression subject.

INFO: The assertion is called every 500 ms.

/**
 * @param {string|Function} expression - source to be executed on device
 * @returns {ChainablePromise.<void|boolean|string>}
 */
async function jsExpression(expression) {}

// Parameter passed as string
const evaluationResult = await suitest.jsExpression('1+2');

// Parameter passed as JS function. Executed on device in a global scope
const evaluationResult = await suitest.jsExpression(function () {return 1 + 2;});

location

location() defines a Current location subject.

/**
 * @returns {ChainablePromise.<void|boolean|string>}
 */
async function location() {}

const currentLocation = await suitest.location();

networkRequest

networkRequest() defines a Network request subject. Used in conjunction with .wasMade(), .willBeMade(), requestMatches() and responseMatches chain modifiers.

Suitest does not allow to assert on a body of a network request/response bigger than 20 KB.

/**
 * @returns {ChainablePromise.<void|boolean>}
 */
async function networkRequest(target, req, res, countPrevious) {}

// Find POST to http://suite.st with response status 200 only in new logs
const requestWillBeMade = await suitest.networkRequest()
    .contains('http://file.suite.st')
    .requestMatches(suitest.NETWORK_PROP.METHOD, suitest.NETWORK_METHOD.POST)
    .responseMatches(suitest.NETWORK_PROP.STATUS, 200)
    .willBeMade();

position

position() defines the position subject, takes coordinates as x and y axis for position on subject.

/**
 * Define position subject
 * @param {number} x - horizontal position
 * @param {number} y - vertical position
 * @returns {ChainablePromise.<void|boolean>}
 */
async function position(x, y) {}

// Click on position
await suitest.position(100, 200)
    .click();

relativePosition

  • LG webOS

relativePosition() defines the position subject, takes coordinates as x and y axis for position on subject with current position of the cursor as the base. If the cursor is our of the reach, middle of the screen is used.

/**
 * Define relative position
 * @param {number} x - horizontal position
 * @param {number} y - vertical position
 * @returns {ChainablePromise.<void|boolean>}
 */
async function relativePosition(x, y) {}

// Click on position relative to the current cursor location
await suitest.relativePosition(100, 200).click();

runTest

runTest() runs a test that is defined and saved inside of the normal Suitest Test editor. Test is ran based on test ID. The test ID can be found inside the Test editor.

Beware of the version change list

By default, the unapplied changes are not included. If you want to use it, please use --include-changelist option in your execution script.

// Run test once
await suitest.assert.runTest('test-id');

// Run test exactly 5x
await suitest.assert.runTest('test-id').repeat(5);

// Run test until ... max 5x
await suitest.assert.runTest('test-id').until(
    suitest.location.equals('https://example.com')
).repeat(5);

// Run test only if ...
if (suitest.location.equals('https://example.com')) {
    await suitest.assert.runTest('test-id');
}

video

video() defines a Video subject.

/**
 * Look up video element
 * @returns {ChainablePromise.<void|boolean|Object>}
 */
async function video() {}

// Look up video element
const elementProps = await suitest.video();

window

window() defines the current window subject, needs to be combined with chain methods and test operation browser commands.

// Current browser window
async function window() {}

//for example - refresh the current browser window
await suitest.window().refresh();