Skip to content

JavaScript API

Repeato allows you to execute scripts via so-called “Script steps”.

Here is the full JavaScript API:

General VariablesDescription
dataAn object that you can use to share data between your steps.
data.scannedTextHolds the string scanned by the last executed “Check for text” step.
workspaceDirThe directory of your workspace.
currentStepIndexThe index of the currently executing step.
testDirThe directory of the current test.
testRunDirThe directory of the current test run.
axiosThe Axios HTTP client. For example: const response = await axios.get('https://example.com').
General MethodsDescription
log(message: object)Log a message or object.
sleep(x: number)Delay execution for x milliseconds.
getResponse(host: string, path: string, headers: object)Send a GET request to a host. Returns an object.
sendPost(host: string, path: string, body: object, acceptHeader: string, headers: object)Send a POST request. Returns an object.
showDialog({ title, content, onConfirm, onClose }: { title: string, content: string, onConfirm?: () => void, onClose?: () => void })Show a dialog whose content supports Markdown, including formatted text, links, and images. Optional onConfirm and onClose callbacks are called for the corresponding actions. Returns a dialog instance with cancel and confirm functions.
BatchRunner Properties and MethodsDescription
batchRunner.testBatchAccess the batch of tests.
batchRunner.currentExceptionHandlerIndexAccess the index of the current exception handler.
batchRunner.currentTestIndexAccess the index of the current test.
batchRunner.batchRunAccess the current batch run. Use log(batchRunner.batchRun) to inspect all properties.
batchRunner.isPlayingIndicates whether the batch runner is currently running.
batchRunner.runModeGet the current run mode.
batchRunner.stop()Stop the batch runner.
await batchRunner.createBatchRunExport()Create an export of the current batch run in the workspace’s batchRuns folder and return its path.
await batchRunner.uploadReport(dirPath: string)Upload the report at dirPath to the Repeato cloud and return the report URL.
batchRunner.setTestBatchById(batchId: string)Set the test batch for the batch runner.
batchRunner.setRunMode(mode: string)Set the run mode to all tests or failed tests only. For example: batchRunner.setRunMode('AllTests') or batchRunner.setRunMode('OnlyFailed').
batchRunner.addOnBatchStart(key: string, callback: (batch: Batch) => void)Run the callback just before the batch starts.
batchRunner.addOnTestFail(key: string, callback: (test: Test, testRun: TestRun, stepResult: StepResult) => void)Run the callback when a test fails.
batchRunner.addOnTestSuccess(key: string, callback: (test: Test, testRun: TestRun) => void)Run the callback when a test succeeds.
batchRunner.addOnBatchCompleted(key: string, callback: (batchRun: BatchRun) => void)Run the callback when the batch completes, whether it succeeds or fails.
batchRunner.removeOnBatchStart(key: string)Remove a callback registered with addOnBatchStart.
batchRunner.removeOnTestFail(key: string)Remove a callback registered with addOnTestFail.
batchRunner.removeOnTestSuccess(key: string)Remove a callback registered with addOnTestSuccess.
batchRunner.removeOnBatchCompleted(key: string)Remove a callback registered with addOnBatchCompleted.
batchRunner.testRunnerAccess all testRunner properties and methods. Use log(batchRunner.testRunner) to inspect them.
TestRunner Properties and MethodsDescription
testRunner.currentTestAccess all properties of the current test. Use log(testRunner.currentTest) to inspect them.
testRunner.currentTestRunAccess the current test run. Use log(testRunner.currentTestRun) to inspect it.
testRunner.lastStepResultAccess the result of the previously executed step. Use log(testRunner.lastStepResult) to inspect it.
testRunner.currentStepIndexThe zero-based index of the current step.
testRunner.setNextStepId(id: string)Set the next step to execute by ID. For example: testRunner.setNextStepId('AH23D6').
testRunner.setNextStepIndex(index: number)Set the next step to execute by its zero-based index.
testRunner.goBackBy(stepCount: number)Go back by stepCount steps and continue execution from there.
testRunner.addOnScreenshotSaved(key: string, listener: (stepResult: StepResult, screenshotPath: string) => void)Run the listener as soon as a screenshot has been saved.
testRunner.addOnStepCompleted(key: string, callback: (stepResult: StepResult) => void)Run the callback whenever a step completes.
testRunner.removeOnScreenshotSaved(key: string)Remove a listener registered with addOnScreenshotSaved.
testRunner.removeOnStepCompleted(key: string)Remove a callback registered with addOnStepCompleted.
testRunner.setScaleInvariantMatchingEnabled(enabled: boolean)Enable or disable scale-invariant matching. It is enabled by default.
DeviceConnector Properties and MethodsDescription
deviceConnector.selectedDeviceDataAll data related to the currently connected device. Use log(deviceConnector.selectedDeviceData) to inspect it.
deviceConnector.sendString(string)Send a string to the device. The app under test must have a focused input field to receive the data.
deviceConnector.clearText()Clear the currently selected input field.
deviceConnector.sendClick(xPerc, yPerc)Send 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(xPerc, yPerc)Send a touch-down event. Each sendDown needs a sendUp; combine it with sendMove to simulate a drag gesture.
deviceConnector.sendMove(xPerc, yPerc)Send a move event. Use sendDown first and finish the drag with sendUp.
deviceConnector.sendUp(xPerc, yPerc)Send a touch-up event.
await deviceConnector.sendAdbCommand(command)Send an Android Debug Bridge (ADB) command.
deviceConnector.addOnDeviceLog(listenerName: string, callback: (log: string) => void)Run the callback for every log line sent by the app under test.
await deviceConnector.sendIdbCommand(command)Send an iOS Development Bridge (IDB) command. For example: await deviceConnector.sendIdbCommand('list-targets').
await deviceConnector.takeScreenshot(filepath)Take a screenshot and save it at filepath.
await deviceConnector.setClipboard(content: string)Set the device clipboard to a string.
await deviceConnector.getClipboard()Get the device clipboard content.
await deviceConnector.vision(prompt: string, region: { x: number, y: number, width: number, height: number } | undefined)Send a prompt and a screenshot of the current device screen to the vision module. Optionally limit the screenshot to a region. Returns a Promise<string>.
AudioTools Properties and MethodsDescription
audioTools.say(text: string)Turn the given text into audio.
audioTools.playAudio(url: string)Play audio from the given URL.
audioTools.stopAudio()Stop the currently playing audio.
audioTools.recordAudio(duration: number)Record audio for the given duration in milliseconds and return the URL of the temporary recording.
EN