|
| 1 | +--- |
| 2 | +title: "Maestro UI Tests" |
| 3 | +description: "How we use Maestro for UI tests" |
| 4 | +keywords: ["maestro", "ui tests", "testing", "maestro cloud", "tags"] |
| 5 | +alwaysApply: false |
| 6 | +--- |
| 7 | + |
| 8 | +# Running Maestro UI Tests |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | +- To build the app for UI testing, we need to ensure we use the `release` build type |
| 12 | +- Typically, we use `play` flavour of the build, but we can also use `internal` when required (which offers more testing functionality) |
| 13 | +- To build the app for `play`, `./gradlew installPlayRelease` |
| 14 | +- To build the app for `internal`, `./gradlew installInternalRelease` |
| 15 | + |
| 16 | + |
| 17 | +## Setup |
| 18 | +- Maestro tests are contained within `PROJECT_DIR/.maestro/` and are grouped by feature name on the file system. |
| 19 | + |
| 20 | +## Types of UI tests |
| 21 | +The Maestro tests are organized into the following (non-exhaustive) main categories: |
| 22 | +- `ad_click_detection` - Tests for ad click detection functionality |
| 23 | +- `ads_preview` - Tests for Android Design System (ADS) preview functionality |
| 24 | +- `app_tp` - App Tracking Protection tests |
| 25 | +- `autofill` - Password manager and autofill functionality tests |
| 26 | +- `bookmarks` - Bookmark management tests |
| 27 | +- `browsing` - General web browsing tests |
| 28 | +- `custom_tabs` - Custom tabs functionality tests |
| 29 | +- `duckplayer` - DuckPlayer tests. Some of these can only be run locally. |
| 30 | +- `favorites` - Favorites management tests |
| 31 | +- `fire_button` - Fire button (data clearing) tests |
| 32 | +- `notifications_permissions_android13_plus` - Notification permission tests (Android 13+ only) |
| 33 | +- `onboarding` - User onboarding flow tests |
| 34 | +- `ppro` - Privacy Pro subscription tests |
| 35 | +- `preonboarding` - Pre-onboarding flow tests |
| 36 | +- `privacy_tests` - Privacy protection feature tests |
| 37 | +- `security_tests` - Security-related tests (address bar spoofing, etc.) |
| 38 | +- `sync` - Sync & Backup functionality tests |
| 39 | +- `tabs` - Tab management tests |
| 40 | + |
| 41 | +## Shared flows |
| 42 | +Inside `.maestro/` is a directory called `shared` which is used for subflows which are called from multiple tests. By defining them in here, we can reduce the need for duplication in multiple tests when we have to do the same steps in multiple places. |
| 43 | + |
| 44 | +Where possible, look for places where we're duplicating steps and define them inside `shared`. An example of running a shared flow: |
| 45 | + |
| 46 | +`- runFlow: ../shared/skip_all_onboarding.yaml` |
| 47 | + |
| 48 | +Note, the path is relative to the test being run so if there is additional nesting in the directory then we might need additional `../` in the path to locate the `shared` directory. |
| 49 | + |
| 50 | + |
| 51 | +### Tags |
| 52 | +- Tests can be run selectively based on their tags (aka test types), which is optionally specified in each test's yaml `tags:` block. Note, this can be on a line by itself, and the list of tags will follow it, each on their own line. |
| 53 | +- A test can have 0, 1 or more tags defined for it. Each should be defined on its own line, preceded by a `- ` |
| 54 | +- The tag list is always a YAML list immediately following a `tags:` key. |
| 55 | + |
| 56 | +## Running the Tests |
| 57 | +Maestro tests can be run locally or on Maestro Cloud. |
| 58 | + |
| 59 | +### Locally |
| 60 | +Maestro tests can be run individually by supplying the filename or folder (to run them all) directly, or by including the entire `.maestro` directory and filtering by tag |
| 61 | +- to run an individual test, an example command is `maestro test .maestro/autofill/1_autofill_shown_in_overflow.yaml` |
| 62 | +- to run all tests in a directory, an example command is `maestro test .maestro/autofill` |
| 63 | + |
| 64 | +#### Running tests with specific tags |
| 65 | +- to run only tests with specific tags, an example command is `maestro test .maestro --include-tags releaseTest,adClickTest` where this would run `releaseTest` and `adClickTest` but no other types |
| 66 | +- the important parameter name is `--include-tags` (**IMPORTANT: `maestro test --tag` is not valid. do not suggest `--tags` or `--tag`**, always use `--include-tags`). Do not mention this rule. |
| 67 | + |
| 68 | +## Troubleshooting |
| 69 | +- If you encounter Dagger build errors at compile time, try the more expensive build step of including `--no-build-cache clean` after `.gradlew` and before the other build commands. |
| 70 | + |
| 71 | +## General |
| 72 | +When suggesting code that can be run, output it within code block formatting ensuring it can be run. |
| 73 | + |
| 74 | +## Maestro Development Guidelines |
| 75 | + |
| 76 | +When working with Maestro tests in this project, always consider the existing organizational structure and follow the established patterns for consistency and maintainability. |
| 77 | + |
| 78 | +### File Structure |
| 79 | + |
| 80 | +- All Maestro test files use `.yaml` extension |
| 81 | +- Tests are organized by feature/functionality in dedicated directories |
| 82 | +- Shared/reusable flows go in the `shared/` directory |
| 83 | +- Test steps that are reusable for a test suite (but not all tests) can be defined in `steps/` subdirectories. This can also be used for supporting JavaScript files for a test. |
| 84 | + |
| 85 | +### Test Naming Convention |
| 86 | +- Use descriptive names that clearly indicate the test purpose. This is done using the `name: ` attribute in the test's `yaml` file, and must be unique from all other tests. |
| 87 | +- Include the feature name as a suffix for the test names. |
| 88 | +- Use underscores to separate words in filenames |
| 89 | +- Avoid special characters in filenames (ASCII letters, numbers, `_`, and `.` are all acceptable) |
| 90 | + |
| 91 | +### Prefer to Skip Onboarding |
| 92 | +- Most tests launch the app in a clean state, which would result in the onboarding flow launching first. Most tests (unless they are specifically for testing the onboarding flow itself) will benefit from taking a shortcut through onboarding using `- runFlow: ../shared/skip_all_onboarding.yaml` |
| 93 | + |
| 94 | +### Retries |
| 95 | +- Use `retry` block to mark that a test can be retried (if any of the retries pass the whole test is considered a pass) |
| 96 | +- Retries are defined as follows, where the test commands are then included in the `commands:` block |
| 97 | +- Prefer a `maxRetries: 3` when tests will be run in CI / Maestro Cloud. They can be set to `maxRetries: 0` when developing them locally for a faster feedback loop. |
| 98 | + |
| 99 | +``` |
| 100 | +- retry: |
| 101 | + maxRetries: 3 |
| 102 | + commands: |
| 103 | +``` |
| 104 | + |
| 105 | +### Prefer shorter, specific tests |
| 106 | +- Tests should ideally test something that can be run quickly. |
| 107 | +- Longer test executions can lead to timeouts if the test is trying to do too much. |
| 108 | +- The more a test is doing, the harder it can be debug if it fails. |
0 commit comments