Skip to content

JavaScript API

Repeato allows you to execute JavaScript using Script steps. The following globals are available while a test or batch is running.

For machine-readable documentation, use the raw Markdown reference or the TypeScript declarations. See JavaScript recipes for complete, executable examples.

Type: object

An object that you can use to share data between steps.

Type: string

The string scanned by the last executed Check for text step.

Type: string

The directory of the current workspace.

Type: number

The zero-based index of the currently executing step.

Type: string

The directory of the current test.

Type: string

The directory of the current test run.

Type: AxiosInstance

The Axios HTTP client.

const response = await axios.get('https://example.com')
Signature
log(message: object)

Logs a message or object.

Signature
sleep(milliseconds: number): Promise<void>

Delays execution for the given number of milliseconds.

Signature
getResponse(host: string, path: string, headers?: object): Promise<string>

Sends a GET request to a host.

Signature
sendPost(
host: string,
path: string,
body: string | object,
acceptHeader?: string,
headers?: object,
): Promise<string>

Sends a POST request.

Signature
showDialog({
title,
content,
onConfirm,
onClose,
}: {
title: string
content: string
onConfirm?: () => void
onClose?: () => void
}): { cancel: Function; confirm: Function }

Shows a dialog whose content supports Markdown, including formatted text, links, and images. The optional callbacks run when the corresponding action occurs. The returned dialog instance can be closed using cancel() or confirm().

Controls the current test batch and provides batch lifecycle hooks.

Type: TestBatch

The current batch of tests.

Type: number

The index of the current exception handler.

Type: number

The index of the current test.

Type: BatchRun

The current batch run. Use log(batchRunner.batchRun) to inspect all properties.

Type: boolean

Indicates whether the batch runner is currently running.

Type: string

The current run mode.

stop(): Promise<void>

Stops the batch runner.

Signature
createBatchRunExport(): Promise<string>

Creates an export of the current batch run in the workspace’s batchRuns folder and returns its path.

Signature
uploadReport(dirPath: string): Promise<string>

Uploads the report at dirPath to the Repeato cloud and returns the report URL.

Signature
batchRunner.setTestBatchById(batchId: string)

Sets the test batch for the batch runner.

Signature
batchRunner.setRunMode(mode: string)

Sets the run mode to all tests or failed tests only.

batchRunner.setRunMode('AllTests')
batchRunner.setRunMode('OnlyFailed')
Signature
batchRunner.addOnBatchStart(key: string, callback: (batch: Batch) => void)

Registers a callback that runs just before the batch starts.

Signature
batchRunner.addOnTestFail(
key: string,
callback: (test: Test, testRun: TestRun, stepResult: StepResult) => void,
)

Registers a callback that runs when a test fails.

Signature
batchRunner.addOnTestSuccess(
key: string,
callback: (test: Test, testRun: TestRun) => void,
)

Registers a callback that runs when a test succeeds.

Signature
batchRunner.addOnBatchCompleted(
key: string,
callback: (batchRun: BatchRun) => void,
)

Registers a callback that runs when the batch completes, whether it succeeds or fails.

Signature
batchRunner.removeOnBatchStart(key: string)

Removes a callback registered with addOnBatchStart().

Signature
batchRunner.removeOnTestFail(key: string)

Removes a callback registered with addOnTestFail().

Signature
batchRunner.removeOnTestSuccess(key: string)

Removes a callback registered with addOnTestSuccess().

Signature
batchRunner.removeOnBatchCompleted(key: string)

Removes a callback registered with addOnBatchCompleted().

Type: TestRunner

Provides access to all testRunner properties and methods. Use log(batchRunner.testRunner) to inspect them.

Controls execution of the current test and exposes step lifecycle hooks.

Type: Test

The current test. Use log(testRunner.currentTest) to inspect all properties.

Type: TestRun

The current test run. Use log(testRunner.currentTestRun) to inspect all properties.

Type: StepResult

The result of the previously executed step. Use log(testRunner.lastStepResult) to inspect all properties.

Type: number

The zero-based index of the current step.

Signature
testRunner.setNextStepId(id: string)

Sets the next step to execute by ID.

testRunner.setNextStepId('AH23D6')
Signature
testRunner.setNextStepIndex(index: number)

Sets the next step to execute by its zero-based index.

Signature
testRunner.goBackBy(stepCount: number)

Moves back by stepCount steps and continues execution from there.

Signature
testRunner.addOnScreenshotSaved(
key: string,
listener: (stepResult: StepResult, screenshotPath: string) => void,
)

Registers a listener that runs as soon as a screenshot has been saved.

Signature
testRunner.addOnStepCompleted(
key: string,
callback: (stepResult: StepResult) => void,
)

Registers a callback that runs whenever a step completes.

Signature
testRunner.removeOnScreenshotSaved(key: string)

Removes a listener registered with addOnScreenshotSaved().

Signature
testRunner.removeOnStepCompleted(key: string)

Removes a callback registered with addOnStepCompleted().

testRunner.setScaleInvariantMatchingEnabled()

Section titled “testRunner.setScaleInvariantMatchingEnabled()”
Signature
testRunner.setScaleInvariantMatchingEnabled(enabled: boolean)

Enables or disables scale-invariant matching. It is enabled by default.

Provides information about and sends commands to the currently connected device.

Type: DeviceData

All data related to the currently connected device. Use log(deviceConnector.selectedDeviceData) to inspect it.

Signature
sendString(value: string): Promise<void>

Sends a string to the device. The app under test must have a focused input field to receive the data.

clearText(): Promise<void>

Clears the currently selected input field.

Signature
sendClick(xPercentage: number, yPercentage: number): Promise<void>

Sends a touch event to the device. Coordinates range from 0 to 1; sendClick(0.5, 0.5) taps the center of the screen.

Signature
sendDown(xPercentage: number, yPercentage: number): Promise<void>

Sends a touch-down event. Each sendDown() needs a sendUp(); combine it with sendMove() to simulate a drag gesture.

Signature
sendMove(xPercentage: number, yPercentage: number): Promise<void>

Sends a move event. Use sendDown() first and finish the drag with sendUp().

Signature
sendUp(xPercentage: number, yPercentage: number): Promise<void>

Sends a touch-up event.

Signature
sendAdbCommand(command: string): Promise<string>

Sends an Android Debug Bridge (ADB) command.

Signature
deviceConnector.addOnDeviceLog(
listenerName: string,
callback: (log: string) => void,
)

Registers a callback that runs for every log line sent by the app under test.

Signature
sendIdbCommand(command: string): Promise<string>

Sends an iOS Development Bridge (IDB) command.

await deviceConnector.sendIdbCommand('list-targets')
Signature
takeScreenshot(filepath: string): Promise<void>

Takes a screenshot and saves it at filepath.

Signature
setClipboard(content: string): Promise<void>

Sets the device clipboard to a string.

getClipboard(): Promise<string>

Gets the device clipboard content.

Signature
vision(
prompt: string,
region: { x: number; y: number; width: number; height: number } | undefined,
): Promise<string>

Sends a prompt and a screenshot of the current device screen to the vision module. Pass a region to limit the screenshot to part of the screen.

Provides text-to-speech, audio playback, and audio recording.

Signature
audioTools.say(text: string)

Turns the given text into audio.

Signature
playAudio(url: string): Promise<number>

Plays audio from the given URL.

audioTools.stopAudio()

Stops the currently playing audio.

Signature
recordAudio(duration: number): Promise<string>

Records audio for the given duration in milliseconds and returns the URL of the temporary recording.

EN