Playwright
Directory structure¶
Mocks¶
The directory structure for mocks should match the structure of the URL they are mocking.
For example, if we were to mock the URL /api/config/account-user/
, the correct path for the mock would be
/playwright/api/config/account-user.ts
If the URL to be mocked includes parameters /api/account/0
, the parameters do not have to be represented in the directory structure. In this case the mock file would be /playwright/mocks/api/account.js
and may export a method such as mockGetAccountById()
.
Bad
# /api/config/accounts/users
/playwright/mocks/api/config/account-user.ts
Good
# /api/config/account-user/
/playwright/mocks/api/config/account-user.ts
# /api/client/integrations/facebook/fetch-accounts/1/
/playwright/mocks/api/client/integrations/facebook/fetch-accounts.ts
# /api/report/report-page-speed/
/playwright/mocks/api/report/report-page-speed.ts
Tests¶
All actual tests, i.e. the ones that use the Playwright test() method should live in the /playwright/tests/
directory.
If the Playwright test is for a page on the CUBED dashboard, it should be live the pages
subdirectory (i.e. /playwright/tests/pages
).
The directory structure for these tests should match the URL being tested. The account token (e.g. c-a-client-uk
) can be omitted from the directory structure if it exists.
For example, if you were to test the URL /c-a-client-uk/reports/dashboard
, the correct path for the test would be /playwright/tests/pages/reports/dashboard.spec.ts
The .spec.ts
suffix is required to be discovered by Playwright.
Bad
# BAD: Account token included
/playwright/tests/pages/c-a-client-uk/reports/dashboard.spec.ts
# BAD: Missing `.spec.ts` suffix
/playwright/tests/pages/reports/dashboard.ts
# BAD: Not in `pages` subdirectory
/playwright/tests/reports/dashboard.ts
Good
/playwright/tests/pages/reports/dashboard.spec.ts