You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Changed fixtures used in accounts that dont need to check sign-in functionality
* Updated testing doc: added fixture info and expanded on POM pattern
* Update testing.md
* Udated testing.md
Added Superbase emulator workaround
E2E tests use [Playwright](https://playwright.dev/) and run against a fully isolated local stack:
495
+
These are the guidelines and best practices we follow when writing E2E tests using [Playwright](https://playwright.dev/) in this project. Following these
496
+
standards ensures consistency, maintainability, and comprehensive test coverage.
497
+
498
+
E2E tests live in `tests/e2e/` and follow the `*.spec.ts` naming convention, when executed they are run against a fully isolated local stack:
497
499
498
-
-**Supabase** (Postgres) via `npx supabase start`
499
-
-**Firebase** (Auth and Storage) via `firebase emulators:start`
500
+
-**Supabase** (Postgres)
501
+
-**Firebase** (Auth and Storage)
500
502
-**Backend API** (`backend/api`)
501
503
-**Next.js frontend** (`web`)
502
504
503
-
Tests live in `tests/e2e/` and follow the `*.e2e.spec.ts` naming convention.
505
+
### Best Practices
506
+
507
+
1. Test one scenario per test - Each test should verify a single behavior.
508
+
2. Keep tests independent - Each test should be fully independent.
509
+
3. Use locators that reflect how users will interact with the application - Outlined in the [Component Selection Hierarchy](###component-selection-hierarchy) below.
510
+
4. Use the Page Object Model (POM) - Keeps the test files lightweight and easily readable at a glance.
511
+
5. Store authentication state - Persist login state via `storageState` and reuse it across tests where needed.
512
+
6. Use fixtures for setup and teardown - Keeps test files lightweight.
513
+
7. Use web-first assertions - Use Playwright's built-in `expect` assertions (e.g., `toBeVisible`, `toHaveText`) which auto-retry until the condition is met.
514
+
8. Use environment variables for config - Store credentials, base URLs, and environment-specific settings in env vars rather than hardcoding them in test files.
515
+
9. Organise tests with a clear folder structure - Separate test files, page objects, fixtures, and helpers into distinct directories for scalability and maintainability.
516
+
10. Integrate with CI/CD - Run Playwright tests in headless mode in your pipeline, alerting you of possible issues early.
504
517
505
518
---
506
519
@@ -603,9 +616,15 @@ This opens a visual browser interface where you can:
603
616
- 🔄 Re-run tests without restarting anything
604
617
- 🕵️ Time-travel debug through test steps
605
618
619
+
Alternatively if you only want to open the Playwright UI you can use:
620
+
621
+
```bash
622
+
npx playwright test --ui
623
+
```
624
+
606
625
### 3. Edit tests and re-run
607
626
608
-
Edit your `*.e2e.spec.ts` file, save, then click **Run** in the Playwright UI.
627
+
Edit your `*.spec.ts` file, save, then click **Run** in the Playwright UI.
609
628
No restart needed for test file changes.
610
629
611
630
### 4. Reset data when needed
@@ -672,10 +691,10 @@ tests/
672
691
└── e2e/
673
692
├── web/
674
693
│ └── specs/
675
-
│ └── auth.e2e.spec.ts
694
+
│ └── auth.spec.ts
676
695
└── backend/
677
696
└── specs/
678
-
└── api.e2e.spec.ts
697
+
└── api.spec.ts
679
698
```
680
699
681
700
### Component Selection Hierarchy
@@ -712,23 +731,62 @@ This hierarchy mirrors how users actually interact with your application, making
712
731
Tests often receive multiple page objects as fixtures (e.g. `homePage`, `authPage`, `profilePage`). This is the **Page
713
732
Object Model** pattern — a way to organize selectors and actions by the area of the app they belong to.
714
733
715
-
**Page objects are not separate browser tabs.** They are all wrappers around the same underlying `page` instance. Each
716
-
class simply encapsulates the selectors and actions relevant to one part of the UI:
734
+
**Page objects** are all wrappers around the same underlying `page` instance. Each
735
+
class simply encapsulates the selectors and actions relevant to an entire page of the application.
736
+
737
+
The `app.ts` file improves scalability by acting as a central hub for page objects and shared modules. Instead of importing 40 different pages into a test, modules can be accessed through `app.ts`, making tests cleaner and easier to maintain. It also supports functionality that spans multiple pages.
**What happens if you call a method on the "wrong" page object?**
@@ -761,20 +819,93 @@ won't find its element and the test will **time out**.
761
819
762
820
```typescript
763
821
// ⚠️ This fails at runtime if navigation hasn't happened yet
764
-
awaitsettingsPage.deleteAccount() // navigates away from profile
765
-
awaitprofilePage.verifyDisplayName(name) // locator not found → timeout
822
+
awaitapp.settings.deleteAccount() // navigates away from profile
823
+
awaitapp.profile.verifyDisplayName(name) // locator not found → timeout
766
824
```
767
825
768
826
Always ensure navigation has completed before calling methods that depend on a specific screen being visible.
769
827
828
+
### Fixtures
829
+
830
+
To further improve readability, and simplify the creation/implimentation of tests, fixtures are used for test case setup and teardown where appropriate.
@@ -868,6 +983,27 @@ For comprehensive troubleshooting guidance beyond testing-specific issues, see
868
983
the [Troubleshooting Guide](troubleshooting.md) which covers development environment setup, database and emulator
869
984
issues, API problems, and more.
870
985
986
+
### Supabase emulator not working
987
+
988
+
There might be compatability issues with the Supabase emulator and your setup this can cause a `Runtime error` on the app pointing to an issue in the `supabase/utils.ts (69: 17)` file, and the Supabase emulator showing a generic `site can't be reached` browser error.
989
+
990
+
The workaround for this is to use a remote db and the local firebase emulator
991
+
992
+
Install DBeaver (contact the main maintainer for the postgres db connection info) to view and edit the database
993
+
994
+
```bash
995
+
# Comment out "Object.assign(process.env, supabaseEnv)" in playwright.config.ts
0 commit comments