Chain types

In JavaScript API you create chains of assertions or operations which allow you to test on a subject within your application. We have separated our chains in to three different types - Assertion, Evaluation and Query chains.


Assertion

Let's take a look at a simple assertion chain:

await suitest.assert.element('elementApiID').exists();

An assertion chain is made up of an assert, subject (in this case element and some chain modifier (in this case exists). The readability and structure of the code should be straight forward. In this example we ask Suitest "check if the element with 'elementApiID' exists", Suitest will then return the chain outcome meaning if the assertion passes or fails.

// Assertion chain examples:

// Element - if it exists or does not
await suitest.assert.element('logo').exists();
await suitest.assert.element('login').doesNot().exist();

// Cookie - if it exists and its value
await suitest.assert.cookie('_ga').exists();
await suitest.assert.cookie('_gid').equals('12345');

// Network request - https url was requested
await suitest.assert.networkRequest().equal('https://suite.st/docs/').wasMade();

Lear more about assertions in Suitest.

Assertion outcome

The chain resolves to no value if the assertion passes, if it is rejected then an AssertionError is thrown.

Evaluation

Chains without the assert assertion look just like the example below.

const elementExists = await suitest.element('elementApiID').exists();

Heads up: You can convert any evaluation chain that does not contain assert to an assertion line by simply adding toAssert() at the end of the chain.

Evaluation outcome

These types of chains resolve to a boolean value and if the chain passes true otherwise false.

Query

A couple special chains return useful values that you may want to use during testing. These chains are created without any additional chain modifiers.

Using the cookie subject, you can check for a particular cookie and gather its value. The value is returned as a string if the cookie is found. If it is not found then undefiend will be returned.

const cookieValue = await suitest.cookie('my-cookie');

element

Using the element subject, you can get element properties which are returned as an object. If the element is not found then undefiend will be returned.

const elementProps = await suitest.element('my-element');

jsExpression

Using the jsExpression subject, you can evaluate a JavaScript expression which returns a string with the result of your expression.

const jsExpressionResult = await suitest.jsExpression('1+2');

location

Using the location subject, you can check the current location of the app which is returned as a string that contains the current location.

const currentLocation = await suitest.location();