JavaScript API
Repeato allows you to execute scripts via so-called “Script steps”.
Here is the full JavaScript API:
| General Variables | Description |
|---|---|
data | An object that you can use to share data between your steps. |
data.scannedText | Holds the string scanned by the last executed “Check for text” step. |
workspaceDir | The directory of your workspace. |
currentStepIndex | The index of the currently executing step. |
testDir | The directory of the current test. |
testRunDir | The directory of the current test run. |
axios | The Axios HTTP client. For example: const response = await axios.get('https://example.com'). |
| General Methods | Description |
|---|---|
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 Methods | Description |
|---|---|
batchRunner.testBatch | Access the batch of tests. |
batchRunner.currentExceptionHandlerIndex | Access the index of the current exception handler. |
batchRunner.currentTestIndex | Access the index of the current test. |
batchRunner.batchRun | Access the current batch run. Use log(batchRunner.batchRun) to inspect all properties. |
batchRunner.isPlaying | Indicates whether the batch runner is currently running. |
batchRunner.runMode | Get 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.testRunner | Access all testRunner properties and methods. Use log(batchRunner.testRunner) to inspect them. |
| TestRunner Properties and Methods | Description |
|---|---|
testRunner.currentTest | Access all properties of the current test. Use log(testRunner.currentTest) to inspect them. |
testRunner.currentTestRun | Access the current test run. Use log(testRunner.currentTestRun) to inspect it. |
testRunner.lastStepResult | Access the result of the previously executed step. Use log(testRunner.lastStepResult) to inspect it. |
testRunner.currentStepIndex | The 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 Methods | Description |
|---|---|
deviceConnector.selectedDeviceData | All 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 Methods | Description |
|---|---|
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. |