<- Blog

Maestro — Announcing JavaScript + HTTP Request Support

Run JavaScript and execute HTTP requests from your Maestro Flows

Leland Takamine December 1, 2022

Maestro Flows have historically been written in pure YAML. This restriction enforces simple, declarative test definitions, which is a big part of why users are drawn to Maestro.

But there are some use cases that don’t fit well into the declarative world. Here are a few examples we’ve heard from real Maestro users:

  • Execute an http request and input part of the response into a text field
  • Ensure that the sum of the prices of in a list match the total price
  • Ensure the label of a list item matches the title in its details screen

These are valid use cases, but the logic would be difficult to encode into YAML syntax even if we considered the introduction of new Maestro APIs. To support these sorts of scenarios, we knew we needed a way to break out of the YAML world to express more complex ideas.

So today, we are excited to announce JavaScript support in Maestro Flows!

JavaScript Support

Full JavaScript Documentation

Don’t worry — Maestro is not becoming a JavaScript framework. But we are opening up a small escape hatch to be used in specific scenarios where YAML is not a good fit.

Here’s how it works:

Everything within ${} blocks is evaluated as JavaScript, allowing you to insert dynamically computed values into any Maestro command:

appId: com.example
env:
    MY_NAME: John
---
- launchApp
- inputText: ${1 + 1}               # Inputs '2'
- inputText: ${'Hello ' + MY_NAME}  # Inputs 'Hello John'
- tapOn: ${MY_NAME}                 # Taps on element with text 'John'

You can also run JavaScript files:

- runScript: myScript.js

Note: Your JavaScript code is evaluated in a sandbox for portability and security reasons. As a result, you only have access to a limited set of built in functions and you can’t access the filesystem.

An important use case we wanted to solve with JavaScript support is the ability to execute HTTP requests. So out-of-the-box, Maestro provides a set of simple HTTP JavaScript functions.

HTTP Request Support

Full HTTP Request Documentation

Here’s an example that executes an HTTP GET request, parses the response, and types part of the output into a text field:

// myScript.js
var response = http.get('https://api.example.com/getName');
output.firstName = json(response.body).first;
# YourFlow.yaml
- runScript: myScript.js
- inputText: ${output.firstName}

Here are the main concepts in the example above:

  • http.post() is a built-in function that executes a POST request
  • json() is another built-in function that parses the response body into an Object
  • output is a built-in global Object variable where you can store computed values
  • inputText uses the stored output.firstName value as its text parameter

With the introduction of JavaScript support and built-in HTTP functions, you can now easily interact with your backend APIs right from your Maestro Flows!

Give it a try!

Head to the documentation to get started with Maestro’s JavaScript support:

https://maestro.mobile.dev/advanced/javascript

We’d love to hear your feedback on this feature. As always, the best place to reach us is on Slack but you can also shoot us an email at hello@mobile.dev.

Follow us on Twitter for updates! @mobile__dev

We're entering a new era of software development. Advancements in AI and tooling have unlocked unprecedented speed, shifting the bottleneck from development velocity to quality control. This is why we built — a modern testing platform that ensures your team can move quickly while maintaining a high standard of quality.

Learn more ->