Have you ever needed to run your AskUI Workflows in parallel on multiple devices to speed up the execution?
That is possible with a little bit of configuration in Jest, the runner used to execute AskUI Workflows, and multiple AskUI Controllers.
This blog will walk you through the setup for two Android devices and running a bunch of workflows.
Prerequisites
- AskUI installed and configured on your system (Windows, Linux, macOS)
- GitHub repository to follow along

Start AskUI Controllers
⚠️ The commands shown below start the AskUI Controller on your local machine as we are controlling two Android devices. If you want to run your workflows on a remote machine, install and start the controllers there. Do not forget to get the IP of the remote machine for the URL to the controller!
Windows
# Open AskUI Shell
askui-shell
# Start first AskUI Controller on Port 6769 for android device 0 (emulator-5556)
AskUI-StartController -RunInBackground -DisplayNum 0 -Runtime android -Port 6769
# Start second AskUI Controller on Port 6770 for android device 1 (emulator-5554)
AskUI-StartController -RunInBackground -DisplayNum 1 -Runtime android -Port 6770Jest
Next comes Jest, the javascript framework AskUI uses to run its workflows.
.env For Configuration Environment Variables
First, we want to have a way to configure how many parallel processes are running workflows. For this, we install the dotenv package like this:
npm install --save-dev dotenvThen we create a file .env in the root of the project and fill it with the following. We set the JEST_MAX_WORKER to two as we have two Android devices:
ASKUI_WORKSPACE_ID=<your_workspace_id>
ASKUI_TOKEN=<your_workspace_token>
JEST_MAX_WORKER=1Configure Maximum Parallel Workers in jest.config.ts
We need the max workers feature from Jest which allows us to specify the number of workers that should run in parallel. It can be configured in the file jest.config.ts. We use the environment variable JEST_MAX_WORKER from the .env file.
import type { Config } from '@jest/types';
import 'dotenv/config';
const config: Config.InitialOptions = {
  preset: 'ts-jest',
  testEnvironment: '@askui/jest-allure-circus',
  setupFilesAfterEnv: ['./helpers/askui-helper.ts'],
  sandboxInjectedGlobals: [
    'Math',
  ],
  maxWorkers: process.env.JEST_MAX_WORKER ? parseInt(process.env.JEST_MAX_WORKER) : 1
};
// eslint-disable-next-line import/no-default-export
export default config;Connect AskUI Controllers in askui-helper.ts
In the askui-helper.ts we hold an array of all AskUI Controller URLs we want to target. We take the configured maxWorkers and the workerId to connect each worker with a different AskUI Controller.
⚠️ If you do not use two Android devices and the AskUI Controller runs on a remote system, you must change the URLs in the uiControllerDeviceList.
import { UiControlClient } from 'askui';
import 'dotenv/config';
// List of AskUI Controller connected to remote devices
const uiControllerDeviceList = ["ws://127.0.0.1:6769", "ws://127.0.0.1:6770"]
// Client is necessary to use the askui API
let aui: UiControlClient;
jest.setTimeout(60 * 1000 * 60);
let maxWorkers: number;
let workerId: number;
let uiControllerUrl: string;
beforeAll(async () => {
  maxWorkers = parseInt(process.env.JEST_MAX_WORKER, 10); // Our env variable defined in .env file
  workerId = parseInt(process.env.JEST_WORKER_ID, 10); // Each Jest Worker starts as its own process and the index begins with 1. See https://jestjs.io/docs/environment-variables#jest_worker_id
  expect(maxWorkers).toBeLessThanOrEqual(uiControllerDeviceList.length)
  // Select one Android Device per Worker
  uiControllerUrl = uiControllerDeviceList[workerId - 1]
  aui = await UiControlClient.build({
    uiControllerUrl: uiControllerUrl,
  });
  await aui.connect();  
  console.log("Jest Worker: ", workerId, "/", maxWorkers, " connect to '", uiControllerUrl, "'")
});
...When you start your run with this configuration you will see that the *.test.ts files will be executed in parallel and ONLY once. Each worker will generate a separate report, giving you detailed insights into the execution.
The important thing is that each worker is completely independent and encapsulated. This means the setup process from askui-helper.ts will run separately for each worker! This ensures that the workflows do not interfere with each other.
Conclusion
With a little bit of Jest configuration and multiple AskUI Controllers you can parallelize the execution of your AskUI Workflows.
If you have questions or need support, do not hesitate to join our Community.





.png)
