Moropo
RoadmapTerms
  • Welcome to Moropo
  • Quick Start
  • Uploading your app
    • Producing an Android Build
    • Producing an iOS Build
    • Uploading Your Build To Moropo
  • Creating Tests
    • Using the Test Creator
    • Test Configuration
    • Test Step Commands
      • addMedia
      • assertNotVisible
      • assertTrue
      • assertVisible
      • back (Android only)
      • clearKeychain (iOS Only)
      • clearState
      • copyTextFrom
      • doubleTapOn
      • eraseText
      • evalScript
      • extendedWaitUntil
      • hideKeyboard
      • inputRandomEmail
      • inputRandomNumber
      • inputRandomPersonName
      • inputRandomText
      • inputText
      • launchApp
      • longPressOn
      • openLink
      • pasteText
      • pressKey
      • repeat
      • runFlow
      • runScript
      • scroll
      • scrollUntilVisible
      • setLocation
      • startRecording
      • stopApp
      • stopRecording
      • swipe
      • takeScreenshot
      • tapOn
      • travel
      • waitForAnimationToEnd
    • Test Step Selectors
    • Importing From Maestro
    • Environment Variables
      • ${BUNDLEID}
      • ${EXPORELEASECHANNEL}
      • ${MOROPO_TEST_EMAIL}
      • ${MOROPO_EMAIL_URL}
    • Advanced Use Cases
      • JavaScript
      • Conditionals
      • Network Connection
      • Drag and Drop
  • Running Tests
    • Manually Trigger a Test Run
    • Scheduling a Test Run
    • Tags
    • Supported Devices
    • Test Execution Limits
    • Flakiness Tolerance & Retries
  • CI Integration
    • Initial CI Setup In Moropo
    • GitHub Action
    • Moropo API
      • Branches
      • Builds
      • Test Runs
      • Tests
  • Test Results
    • Results Explorer
    • Slack Reporting
    • Email Reporting
  • App Frameworks
    • Flutter
    • React Native
  • Guides
    • React Native Expo
    • Access Emails During A Test Flow
    • Git workflow using Moropo API
  • Infrastructure
    • IP Addresses
  • Security
    • Services Infrastructure
    • Security Best Practices
Powered by GitBook
On this page
  • Creating a script
  • Execute a script
  • Using Variables
  • Making HTTP Requests
  • HTTP request methods
  • Headers
  • JSON parsing

Was this helpful?

Edit on GitHub
  1. Creating Tests
  2. Advanced Use Cases

JavaScript

Last updated 12 months ago

Was this helpful?

Moropo uses Maestro's GraalJS engine to execute JavaScript steps inside your tests.

This provides a similar JavaScript environment to NodeJS.

Note: it's not currently possible to import node_modules

Creating a script

Add or upload a script directly from the Test Editor

Execute a script

Using Variables

output is a special JavaScript object which is shared by each test run and can be used to store variables for use in your tests.

For example, I could set output.name inside my JavaScript file called get name:

output.name = 'billy'

In my test, I can then access this by calling runScript and then using ${} to access the variable.

For example:

IMPORTANT NOTE Moropo does not currently persist JavaScript data between 'plays' in the Test Editor If a step requires a data set by JS, you must also select the dependent step when playing that step.

For example, in the below case step 3 requires a variable set by step 2. Every time I wish to play step 3, I must also select step 2.

Making HTTP Requests

You can make HTTP requests using the built-in library.

For example, to make a simple GET request, filter the data, and save it to a variable:

const response = http.get("https://jsonplaceholder.typicode.com/users");

output.name = json(response.body).find(user => user.id === 2).name

HTTP request methods

  • http.get("https://myendpoint.com")

  • http.post("https://myendpoint.com")

  • http.put("https://myendpoint.com")

  • http.delete("https://myendpoint.com")

Headers

Headers can be passed using the headers parameter

const response = http.get('https://myendpoint.com', {
    headers: {
        Authorization: 'Bearer myToken'
    }
})

JSON parsing

Use the json() built-in helper function to parse JSON responses.

const response = http.get("https://jsonplaceholder.typicode.com/users");
const users = json(response.body);
// users = [
//   { id: 1, name: "Clive" },
//   { id: 2, name: "Barbie" }
// ]

output.name = users.find(user => user.id === 2).name;
// output.name = Barbie

Use the to call a script during a test run.

runScript command