Skip to content

Commit

Permalink
test: add maestro tests with playwright adapter (react-navigation#12077)
Browse files Browse the repository at this point in the history
This adds some basic Maestro tests. Note that most tests are not testing much, but once we have basic setup, we can update them as we go.

Currently need to be run locally as I haven't been successful with CI setup for Android yet.

This also adds custom logic that runs the Maestro tests to run with Playwright for Web, so we can reuse the same tests. We'll need to update the logic as we add more tests.
  • Loading branch information
satya164 authored Jul 31, 2024
1 parent ca64015 commit 4437da1
Show file tree
Hide file tree
Showing 44 changed files with 366 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

integration-test:
e2e-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -78,8 +78,8 @@ jobs:
- name: Build example for web
run: yarn example expo export --platform web

- name: Run integration tests
run: yarn example test
- name: Run e2e tests
run: yarn example e2e:web

build:
runs-on: ubuntu-latest
Expand Down
18 changes: 15 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ npx playwright install
Run the e2e tests by:

```sh
yarn example test --ui
yarn example e2e:web --ui
```

By default, this will use the local dev server for the app. If you want to test a production build, first build the [example app](/example/) for web:
Expand All @@ -66,7 +66,19 @@ yarn example expo export --platform web
Then run the tests with the `CI` environment variable:

```sh
CI=1 yarn example test
CI=1 yarn example e2e:web
```

Before running Maestro tests:

- Install it following the instructions [here](https://maestro.mobile.dev/getting-started/installing-maestro).
- Start the Emulator or Simulator and install the Expo Go app.
- Start the Metro server with `yarn example start`.

Then run the Maestro tests by:

```sh
yarn example e2e:native
```

### Commit message convention
Expand All @@ -77,7 +89,7 @@ We follow the [conventional commits specification](https://www.conventionalcommi
- `feat`: new features, e.g. add new method to the module.
- `refactor`: code refactor, e.g. migrate from class components to hooks.
- `docs`: changes to documentation, e.g. add usage example for the module.
- `test`: adding or updating tests, eg add integration tests using detox.
- `test`: adding or updating tests, eg add e2e tests using maestro.
- `chore`: tooling changes, e.g. change CI config.

Our pre-commit hooks verify that your commit message matches this format when committing.
Expand Down
7 changes: 7 additions & 0 deletions example/e2e/maestro/auth-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Auth Flow
---
- openLink:
link: exp://127.0.0.1:8081/--/auth-flow
- assertVisible:
text: 'Sign in'
7 changes: 7 additions & 0 deletions example/e2e/maestro/bottom-tabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Bottom Tabs
---
- openLink:
link: exp://127.0.0.1:8081/--/bottom-tabs
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/drawer-view.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Drawer View
---
- openLink:
link: exp://127.0.0.1:8081/--/drawer-view
- assertVisible:
text: 'Drawer Layout'
7 changes: 7 additions & 0 deletions example/e2e/maestro/dynamic-tabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Dynamic Tabs
---
- openLink:
link: exp://127.0.0.1:8081/--/dynamic-tabs
- assertVisible:
text: 'Tab 0'
7 changes: 7 additions & 0 deletions example/e2e/maestro/link-component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Link Component
---
- openLink:
link: exp://127.0.0.1:8081/--/link-component
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/linking-screen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Linking Screen
---
- openLink:
link: exp://127.0.0.1:8081/--/linking-screen
- assertVisible:
text: 'Sign in'
7 changes: 7 additions & 0 deletions example/e2e/maestro/master-detail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Master Detail
---
- openLink:
link: exp://127.0.0.1:8081/--/master-detail
- assertVisible:
text: 'Pages'
7 changes: 7 additions & 0 deletions example/e2e/maestro/material-top-tabs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Material Top Tabs
---
- openLink:
link: exp://127.0.0.1:8081/--/material-top-tabs-screen
- assertVisible:
text: 'Material Top Tabs'
7 changes: 7 additions & 0 deletions example/e2e/maestro/mixed-header-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Mixed Header Mode
---
- openLink:
link: exp://127.0.0.1:8081/--/mixed-header-mode
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/mixed-native-stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Mixed Native Stack
---
- openLink:
link: exp://127.0.0.1:8081/--/mixed-native-stack
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/mixed-stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Mixed Stack
---
- openLink:
link: exp://127.0.0.1:8081/--/mixed-stack
- assertVisible:
text: 'Article by Gandalf'
27 changes: 27 additions & 0 deletions example/e2e/maestro/modal-stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
appId: ${APP_ID}
name: Modal Stack
---
- openLink:
link: exp://127.0.0.1:8081/--/modal-stack
- assertVisible:
text: 'Article by Gandalf'
- tapOn:
text: 'Push albums'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
- tapOn:
text: 'Push article'
retryTapIfNoChange: false
- assertVisible:
text: 'Article by Babel fish'
- tapOn:
text: 'Go back'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
- tapOn:
text: 'Go back'
retryTapIfNoChange: false
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/native-stack-header-customization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Native Stack Header Customization
---
- openLink:
link: exp://127.0.0.1:8081/--/native-stack-header-customization
- assertVisible:
text: 'What is Lorem Ipsum?'
7 changes: 7 additions & 0 deletions example/e2e/maestro/native-stack-prevent-remove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Native Stack Prevent Remove
---
- openLink:
link: exp://127.0.0.1:8081/--/native-stack-prevent-remove
- assertVisible:
text: 'Input'
42 changes: 42 additions & 0 deletions example/e2e/maestro/native-stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
appId: ${APP_ID}
name: Native Stack
---
- openLink:
link: exp://127.0.0.1:8081/--/native-stack
- assertVisible:
text: 'Article by Gandalf'
- tapOn:
text: 'Push feed'
retryTapIfNoChange: false
- assertVisible:
text: 'Feed'
- tapOn:
text: 'Push albums'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
- tapOn:
text: 'Navigate to article'
retryTapIfNoChange: false
- assertVisible:
text: 'Article by Babel fish'
- tapOn:
text: 'Replace with feed'
retryTapIfNoChange: false
- assertVisible:
text: 'Feed'
- tapOn:
text: 'Go back'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
- tapOn:
text: 'Pop by 2'
retryTapIfNoChange: false
- assertVisible:
text: 'Article by Gandalf'
- tapOn:
text: 'Pop to albums'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
7 changes: 7 additions & 0 deletions example/e2e/maestro/navigator-layout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Navigator Layout
---
- openLink:
link: exp://127.0.0.1:8081/--/navigator-layout
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/screen-layout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Screen Layout
---
- openLink:
link: exp://127.0.0.1:8081/--/screen-layout
- assertVisible:
text: 'Suspense & ErrorBoundary'
37 changes: 37 additions & 0 deletions example/e2e/maestro/simple-stack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
appId: ${APP_ID}
name: Simple Stack
---
- openLink:
link: exp://127.0.0.1:8081/--/simple-stack
- assertVisible:
text: 'Article by Gandalf'
- tapOn:
text: 'Update params'
retryTapIfNoChange: false
- assertVisible:
text: 'Article by Babel fish'
- tapOn:
text: 'Replace with feed'
retryTapIfNoChange: false
- assertVisible:
text: 'Feed'
- tapOn:
text: 'Navigate to albums'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
- tapOn:
text: 'Push article'
retryTapIfNoChange: false
- assertVisible:
text: 'Article by Babel fish'
- tapOn:
text: 'Pop to albums'
retryTapIfNoChange: false
- assertVisible:
text: 'Albums'
- tapOn:
text: 'Pop by 2'
retryTapIfNoChange: false
- assertVisible:
text: 'Feed'
7 changes: 7 additions & 0 deletions example/e2e/maestro/stack-header-customization.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Stack Header Customization
---
- openLink:
link: exp://127.0.0.1:8081/--/stack-header-customization
- assertVisible:
text: 'Article by Gandalf'
7 changes: 7 additions & 0 deletions example/e2e/maestro/stack-preload-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Stack Preload Flow
---
- openLink:
link: exp://127.0.0.1:8081/--/stack-preload-flow
- assertVisible:
text: 'Home'
7 changes: 7 additions & 0 deletions example/e2e/maestro/stack-prevent-remove.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Stack Prevent Remove
---
- openLink:
link: exp://127.0.0.1:8081/--/stack-prevent-remove
- assertVisible:
text: 'Input'
7 changes: 7 additions & 0 deletions example/e2e/maestro/stack-transparent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Stack Transparent
---
- openLink:
link: exp://127.0.0.1:8081/--/stack-transparent
- assertVisible:
text: 'Article'
7 changes: 7 additions & 0 deletions example/e2e/maestro/static-screen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Static Screen
---
- openLink:
link: exp://127.0.0.1:8081/--/static-screen
- assertVisible:
text: 'Albums'
7 changes: 7 additions & 0 deletions example/e2e/maestro/tab-preload-flow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Tab Preload Flow
---
- openLink:
link: exp://127.0.0.1:8081/--/tab-preload-flow
- assertVisible:
text: 'Home'
7 changes: 7 additions & 0 deletions example/e2e/maestro/tab-view.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: ${APP_ID}
name: Tab View
---
- openLink:
link: exp://127.0.0.1:8081/--/tab-view
- assertVisible:
text: 'TabView Examples'
6 changes: 3 additions & 3 deletions example/e2e/tests/Link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test('goes to the album screen and goes back', async ({ page }) => {
await page.waitForURL('**/link-component/article/gandalf');

const link = page.getByRole('link', {
name: 'Go to Albums',
name: 'Go to albums',
});

await expect(link).toHaveAttribute('href', '/link-component/albums');
Expand Down Expand Up @@ -58,7 +58,7 @@ test('replaces article with the album screen', async ({ page }) => {
await page.waitForURL('**/link-component/article/gandalf');

const link = page.getByRole('link', {
name: 'Replace with Albums',
name: 'Replace with albums',
});

await expect(link).toHaveAttribute('href', '/link-component/albums');
Expand Down Expand Up @@ -102,7 +102,7 @@ test('preserves hash for navigation', async ({ page }) => {
'Article by Babel fish - React Navigation Example'
);

await page.getByRole('link', { name: 'Replace with Albums' }).click();
await page.getByRole('link', { name: 'Replace with albums' }).click();

await page.waitForURL('**/link-component/albums');
});
Loading

0 comments on commit 4437da1

Please sign in to comment.