Skip to content

Commit 12121e4

Browse files
author
Sergei Iartsev
committed
docs(maestro): added best practices and patterns, fix MAESTRO_
1 parent 4ae68ff commit 12121e4

1 file changed

Lines changed: 45 additions & 11 deletions

File tree

docs/cloud/intro/maestro.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,37 @@ marathon-cloud run maestro android --application your_app.apk --test-application
3131
</TabItem>
3232
</Tabs>
3333

34-
### Command Breakdown
3534
Here's a breakdown of the variables and flags used in the example:
36-
- ./path/to/tests - the root directory containing all your Maestro test files
37-
- folder_or_file_to_execute - a space-separated list of specific folders and files you want to run within the test directory. **Note:** Marathon Cloud does not execute tests from subfolders when a folder is specified.
38-
For iOS:
39-
- --application your_application.app - path to the [iOS application](/intro/ios#application-and-test-application)
40-
For Android:
41-
- --application your_app.apk - path to the [Android application](/intro/android#application-and-test-application)
35+
- `./path/to/tests` - the root directory containing all your Maestro test files
36+
- `folder_or_file_to_execute` - a space-separated list of specific folders and files you want to run within the test directory.
37+
**Note:** Marathon Cloud does not execute tests from subfolders when a folder is specified. To change this behaviour
38+
use [Maestro inclusion patterns](https://docs.maestro.dev/cli/test-suites-and-reports#inclusion-patterns)
39+
- `--application your_application.app` - path to the [iOS application](/intro/ios#application-and-test-application)
40+
- `--application your_app.apk` - path to the [Android application](/intro/android#application-and-test-application)
4241

4342
### Maestro environment variables
44-
If your Maestro tests rely on environment variables, you'll need to pass them to Marathon Cloud.
45-
A common use case is referencing the application ID in a test flow, as shown in this example:
43+
Maestro tests often require environment variables to handle
44+
dynamic data like usernames, API keys or appId. To pass these variables to your tests on Marathon Cloud, you use the **--maestro-env** flag.
45+
46+
To pass a custom environment variable, reference it within your Maestro test using the ${VARIABLE\_NAME} syntax.
47+
All variables must start with MAESTRO_.
48+
For example, to use a username variable:
49+
```shell
50+
appId: your.app.id
51+
---
52+
- launchApp
53+
- inputText: ${MAESTRO_USERNAME}
54+
```
55+
56+
You pass variables as key-value pairs (KEY=VALUE). For instance, to set MAESTRO_USERNAME to MY_USER_NAME:
57+
```shell
58+
export MARATHON_CLOUD_API_KEY=generated_api_key
59+
marathon-cloud run maestro android --application your_app.apk --test-application ./path/to/tests --maestro-env=MAESTRO_USERNAME=MY_USER_NAME folder_or_file_to_execute
60+
61+
```
62+
**Important:**
63+
When you need to reference the application ID (appId) within a Maestro test, you must use a special variable name.
64+
If your test flow requires the **APP_ID** to be a variable:
4665
```shell
4766
# flow.yaml
4867

@@ -51,12 +70,15 @@ appId: ${APP_ID}
5170
- launchApp
5271
- tapOn: "Text on the screen"
5372
```
54-
To provide the value for **APP_ID**, use the **--maestro-env** flag. For instance, to set **APP_ID** to **your.app.id**, you would execute the following command:
73+
You must pass the application ID using the **MAESTRO_APP_ID** environment variable.
5574
```shell
5675
export MARATHON_CLOUD_API_KEY=generated_api_key
57-
marathon-cloud run maestro android --application your_app.apk --test-application ./path/to/tests --maestro-env=APP_ID=your.app.id folder_or_file_to_execute
76+
marathon-cloud run maestro android --application your_app.apk --test-application ./path/to/tests --maestro-env=MAESTRO_APP_ID=your.app.id folder_or_file_to_execute
5877

5978
```
79+
This specific handling for appId is required to ensure predictable behavior and prevent unexpected test failures.
80+
We invite you to leave a comment [here](https://github.com/mobile-dev-inc/Maestro/issues/1789)
81+
if you agree that Maestro should support MAESTRO_APP_ID for the app ID.
6082

6183
### Maestro filtering
6284
For more granular control over which tests run, you can use Maestro's tag-based filtering in addition to the recommended practice of organizing tests into folders.
@@ -81,3 +103,15 @@ Next, pass this filter file to your Marathon Cloud command using the **--filter-
81103
export MARATHON_CLOUD_API_KEY=generated_api_key
82104
marathon-cloud run maestro android --application your_app.apk --test-application ./path/to/tests --filter-file filter.yaml folder_or_file_to_execute
83105
```
106+
### Best practices
107+
To ensure optimal performance and reliability of your test suite, adhere to these structural recommendations when using Marathon Cloud and Maestro.
108+
109+
**Key Recommendations**
110+
- **Test Duration**: Keep individual test flows short.
111+
We recommend a duration of 40 to 80 seconds, and no more than 3 minutes. This practice improves execution speed and simplifies debugging.
112+
- **Test Independence**: Each test flow should be self-contained and capable of running on a fresh device.
113+
If a test requires a specific state, such as a user login, include the setup steps at the beginning of that test's flow.
114+
- **Enable Parallelism**: Marathon Cloud runs multiple tests concurrently.
115+
To leverage this feature, structure your test suite by placing each flow in a separate, independent YAML file. Flows within a single file are executed sequentially as one test and will not be parallelized.
116+
117+

0 commit comments

Comments
 (0)