Execute command - operation

  • Android - WebView apps
  • Browsers
  • HbbTV / Freeview Play
  • LG webOS
  • PlayStation 4/5
  • Samsung Tizen
  • VIDAA
  • Vizio SmartCast
  • Xbox (One, Series X/S) - HTML apps
  • Xfinity (Comcast)
  • Other Smart TVs and STBs - HTML apps

This operation runs arbitrary JavaScript code directly on the device.


To perform this operation in the Suitest Test editor use the Execute command line:

Enable the hidden debug mode

To perform this operation in the Suitest JavaScript API use the executeCommand command:

await suitest.executeCommand("window.myApp.debugMode = 1");

Usage

Sometimes it is necessary to make certain preparations for the test scenario or augment the app to make it behave in a certain way. For example you may want to turn off pop-ups, set a specific location for your app, turn on the debug mode, etc.

Execute command will execute the specified JavaScript on the client without collecting the results. However should the JavaScript code produce an exception the test scenario will fail with the exception message.

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.

Asynchronous JavaScript expressions

If your JavaScript expression resolves to a Promise A+ compatible object, Suitest will wait for promise to resolve before continuing to the next line.

For example, this expression would run asynchronously and will be resolved with 1 second delay:

new Promise(function(resolve) {
    setTimeout(function() {
        resolve();
    }, 1000);
});

It is important for your expression to always resolve, otherwise line will be marked as failed with timeout.

In case Promise rejects, line will be marked as failed - same as if your code would throw an Error.

Important: Suitest does not include polyfills. If you want to use Promise on older devices, you might need to include a polyfill into your application.