JavaScript expression - test subject

JavaScript expression test subject runs the specified JavaScript code on the connected device.


Usage

It is sometimes necessary to perform a test that requires calculation or other manipulation with the app properties. To do this use JavaScript expression test subject. This subject is currently available only on HTML based platforms.

In Test Editor:

Line with JavaScript expression
Line with JavaScript expression

In Suitest API:

await suitest.assert.jsExpression("window.innerHeight;").equals('720');

Only the result from last statement is used for assertion evaluation. The evaluation result is then compared with the expected value as string.

If the code triggers any exceptions then those will be considered test errors and reported accordingly.

You can specify an arbitrary JavaScript code but be careful about the code that produces side effects. For example, consider a silly piece of code like this:

var a = 1;

This code is creating a variable in the global scope. If the application happens to use such variable internally, this code may just have corrupted its runtime and thus the test results can not be considered reliable anymore.

Generally you should use this subject only if you are sure that there is no other way to achieve the desired result. When in doubt on how to structure your JavaScript consult with your development team.

Suitest does not transpile JavaScript for older device, this means that you may get exceptions on some older devices, when using for example const in your expression.