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.
Globals
Section titled “Globals”Type: object
An object that you can use to share data between steps.
data.scannedText
Section titled “data.scannedText”Type: string
The string scanned by the last executed Check for text step.
workspaceDir
Section titled “workspaceDir”Type: string
The directory of the current workspace.
currentStepIndex
Section titled “currentStepIndex”Type: number
The zero-based index of the currently executing step.
testDir
Section titled “testDir”Type: string
The directory of the current test.
testRunDir
Section titled “testRunDir”Type: string
The directory of the current test run.
Type: AxiosInstance
The Axios HTTP client.
const response = await axios.get('https://example.com')log(message: object)Logs a message or object.
sleep()
Section titled “sleep()”sleep(milliseconds: number): Promise<void>Delays execution for the given number of milliseconds.
getResponse()
Section titled “getResponse()”getResponse(host: string, path: string, headers?: object): Promise<string>Sends a GET request to a host.
sendPost()
Section titled “sendPost()”sendPost( host: string, path: string, body: string | object, acceptHeader?: string, headers?: object,): Promise<string>Sends a POST request.
showDialog()
Section titled “showDialog()”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().
batchRunner
Section titled “batchRunner”Controls the current test batch and provides batch lifecycle hooks.
batchRunner.testBatch
Section titled “batchRunner.testBatch”Type: TestBatch
The current batch of tests.
batchRunner.currentExceptionHandlerIndex
Section titled “batchRunner.currentExceptionHandlerIndex”Type: number
The index of the current exception handler.
batchRunner.currentTestIndex
Section titled “batchRunner.currentTestIndex”Type: number
The index of the current test.
batchRunner.batchRun
Section titled “batchRunner.batchRun”Type: BatchRun
The current batch run. Use log(batchRunner.batchRun) to inspect all properties.
batchRunner.isPlaying
Section titled “batchRunner.isPlaying”Type: boolean
Indicates whether the batch runner is currently running.
batchRunner.runMode
Section titled “batchRunner.runMode”Type: string
The current run mode.
batchRunner.stop()
Section titled “batchRunner.stop()”stop(): Promise<void>Stops the batch runner.
batchRunner.createBatchRunExport()
Section titled “batchRunner.createBatchRunExport()”createBatchRunExport(): Promise<string>Creates an export of the current batch run in the workspace’s batchRuns folder and returns its path.
batchRunner.uploadReport()
Section titled “batchRunner.uploadReport()”uploadReport(dirPath: string): Promise<string>Uploads the report at dirPath to the Repeato cloud and returns the report URL.
batchRunner.setTestBatchById()
Section titled “batchRunner.setTestBatchById()”batchRunner.setTestBatchById(batchId: string)Sets the test batch for the batch runner.
batchRunner.setRunMode()
Section titled “batchRunner.setRunMode()”batchRunner.setRunMode(mode: string)Sets the run mode to all tests or failed tests only.
batchRunner.setRunMode('AllTests')batchRunner.setRunMode('OnlyFailed')batchRunner.addOnBatchStart()
Section titled “batchRunner.addOnBatchStart()”batchRunner.addOnBatchStart(key: string, callback: (batch: Batch) => void)Registers a callback that runs just before the batch starts.
batchRunner.addOnTestFail()
Section titled “batchRunner.addOnTestFail()”batchRunner.addOnTestFail( key: string, callback: (test: Test, testRun: TestRun, stepResult: StepResult) => void,)Registers a callback that runs when a test fails.
batchRunner.addOnTestSuccess()
Section titled “batchRunner.addOnTestSuccess()”batchRunner.addOnTestSuccess( key: string, callback: (test: Test, testRun: TestRun) => void,)Registers a callback that runs when a test succeeds.
batchRunner.addOnBatchCompleted()
Section titled “batchRunner.addOnBatchCompleted()”batchRunner.addOnBatchCompleted( key: string, callback: (batchRun: BatchRun) => void,)Registers a callback that runs when the batch completes, whether it succeeds or fails.
batchRunner.removeOnBatchStart()
Section titled “batchRunner.removeOnBatchStart()”batchRunner.removeOnBatchStart(key: string)Removes a callback registered with addOnBatchStart().
batchRunner.removeOnTestFail()
Section titled “batchRunner.removeOnTestFail()”batchRunner.removeOnTestFail(key: string)Removes a callback registered with addOnTestFail().
batchRunner.removeOnTestSuccess()
Section titled “batchRunner.removeOnTestSuccess()”batchRunner.removeOnTestSuccess(key: string)Removes a callback registered with addOnTestSuccess().
batchRunner.removeOnBatchCompleted()
Section titled “batchRunner.removeOnBatchCompleted()”batchRunner.removeOnBatchCompleted(key: string)Removes a callback registered with addOnBatchCompleted().
batchRunner.testRunner
Section titled “batchRunner.testRunner”Type: TestRunner
Provides access to all testRunner properties and methods. Use log(batchRunner.testRunner) to inspect them.
testRunner
Section titled “testRunner”Controls execution of the current test and exposes step lifecycle hooks.
testRunner.currentTest
Section titled “testRunner.currentTest”Type: Test
The current test. Use log(testRunner.currentTest) to inspect all properties.
testRunner.currentTestRun
Section titled “testRunner.currentTestRun”Type: TestRun
The current test run. Use log(testRunner.currentTestRun) to inspect all properties.
testRunner.lastStepResult
Section titled “testRunner.lastStepResult”Type: StepResult
The result of the previously executed step. Use log(testRunner.lastStepResult) to inspect all properties.
testRunner.currentStepIndex
Section titled “testRunner.currentStepIndex”Type: number
The zero-based index of the current step.
testRunner.setNextStepId()
Section titled “testRunner.setNextStepId()”testRunner.setNextStepId(id: string)Sets the next step to execute by ID.
testRunner.setNextStepId('AH23D6')testRunner.setNextStepIndex()
Section titled “testRunner.setNextStepIndex()”testRunner.setNextStepIndex(index: number)Sets the next step to execute by its zero-based index.
testRunner.goBackBy()
Section titled “testRunner.goBackBy()”testRunner.goBackBy(stepCount: number)Moves back by stepCount steps and continues execution from there.
testRunner.addOnScreenshotSaved()
Section titled “testRunner.addOnScreenshotSaved()”testRunner.addOnScreenshotSaved( key: string, listener: (stepResult: StepResult, screenshotPath: string) => void,)Registers a listener that runs as soon as a screenshot has been saved.
testRunner.addOnStepCompleted()
Section titled “testRunner.addOnStepCompleted()”testRunner.addOnStepCompleted( key: string, callback: (stepResult: StepResult) => void,)Registers a callback that runs whenever a step completes.
testRunner.removeOnScreenshotSaved()
Section titled “testRunner.removeOnScreenshotSaved()”testRunner.removeOnScreenshotSaved(key: string)Removes a listener registered with addOnScreenshotSaved().
testRunner.removeOnStepCompleted()
Section titled “testRunner.removeOnStepCompleted()”testRunner.removeOnStepCompleted(key: string)Removes a callback registered with addOnStepCompleted().
testRunner.setScaleInvariantMatchingEnabled()
Section titled “testRunner.setScaleInvariantMatchingEnabled()”testRunner.setScaleInvariantMatchingEnabled(enabled: boolean)Enables or disables scale-invariant matching. It is enabled by default.
deviceConnector
Section titled “deviceConnector”Provides information about and sends commands to the currently connected device.
deviceConnector.selectedDeviceData
Section titled “deviceConnector.selectedDeviceData”Type: DeviceData
All data related to the currently connected device. Use log(deviceConnector.selectedDeviceData) to inspect it.
deviceConnector.sendString()
Section titled “deviceConnector.sendString()”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.
deviceConnector.clearText()
Section titled “deviceConnector.clearText()”clearText(): Promise<void>Clears the currently selected input field.
deviceConnector.sendClick()
Section titled “deviceConnector.sendClick()”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.
deviceConnector.sendDown()
Section titled “deviceConnector.sendDown()”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.
deviceConnector.sendMove()
Section titled “deviceConnector.sendMove()”sendMove(xPercentage: number, yPercentage: number): Promise<void>Sends a move event. Use sendDown() first and finish the drag with sendUp().
deviceConnector.sendUp()
Section titled “deviceConnector.sendUp()”sendUp(xPercentage: number, yPercentage: number): Promise<void>Sends a touch-up event.
deviceConnector.sendAdbCommand()
Section titled “deviceConnector.sendAdbCommand()”sendAdbCommand(command: string): Promise<string>Sends an Android Debug Bridge (ADB) command.
deviceConnector.addOnDeviceLog()
Section titled “deviceConnector.addOnDeviceLog()”deviceConnector.addOnDeviceLog( listenerName: string, callback: (log: string) => void,)Registers a callback that runs for every log line sent by the app under test.
deviceConnector.sendIdbCommand()
Section titled “deviceConnector.sendIdbCommand()”sendIdbCommand(command: string): Promise<string>Sends an iOS Development Bridge (IDB) command.
await deviceConnector.sendIdbCommand('list-targets')deviceConnector.takeScreenshot()
Section titled “deviceConnector.takeScreenshot()”takeScreenshot(filepath: string): Promise<void>Takes a screenshot and saves it at filepath.
deviceConnector.setClipboard()
Section titled “deviceConnector.setClipboard()”setClipboard(content: string): Promise<void>Sets the device clipboard to a string.
deviceConnector.getClipboard()
Section titled “deviceConnector.getClipboard()”getClipboard(): Promise<string>Gets the device clipboard content.
deviceConnector.vision()
Section titled “deviceConnector.vision()”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.
audioTools
Section titled “audioTools”Provides text-to-speech, audio playback, and audio recording.
audioTools.say()
Section titled “audioTools.say()”audioTools.say(text: string)Turns the given text into audio.
audioTools.playAudio()
Section titled “audioTools.playAudio()”playAudio(url: string): Promise<number>Plays audio from the given URL.
audioTools.stopAudio()
Section titled “audioTools.stopAudio()”audioTools.stopAudio()Stops the currently playing audio.
audioTools.recordAudio()
Section titled “audioTools.recordAudio()”recordAudio(duration: number): Promise<string>Records audio for the given duration in milliseconds and returns the URL of the temporary recording.