Skip to content

Commit 02eeaca

Browse files
SuaYooemma-sg
andauthored
test: Update Playwright E2E test settings (#2247)
- Moves E2E test user to dedicated env variables - Fixes playwright test redirect issue --------- Co-authored-by: Emma Segal-Grossman <hi@emma.cafe>
1 parent daae821 commit 02eeaca

File tree

7 files changed

+42
-15
lines changed

7 files changed

+42
-15
lines changed

.github/workflows/ui-tests-playwright.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ jobs:
1414
timeout-minutes: 60
1515
runs-on: ubuntu-latest
1616
env:
17-
DEV_PASSWORD: ${{ secrets.DEV_PASSWORD }}
17+
E2E_USER_EMAIL: ${{ secrets.E2E_USER_EMAIL }}
18+
E2E_USER_PASSWORD: ${{ secrets.E2E_USER_PASSWORD }}
1819
API_BASE_URL: ${{ secrets.API_BASE_URL }}
1920
working-directory: ./frontend
2021
steps:
@@ -65,7 +66,8 @@ jobs:
6566
run: |
6667
cd frontend
6768
touch .env
68-
echo DEV_PASSWORD="${{ secrets.DEV_PASSWORD }}" >> .env
69+
echo E2E_USER_EMAIL="${{ secrets.E2E_USER_EMAIL }}" >> .env
70+
echo E2E_USER_PASSWORD="${{ secrets.E2E_USER_PASSWORD }}" >> .env
6971
echo API_BASE_URL=${{ secrets.API_BASE_URL }} >> .env
7072
cat .env
7173

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@
125125
"@open-wc/testing": "^3.2.0",
126126
"@playwright/test": "1.49.0",
127127
"@web/test-runner": "^0.13.22",
128-
"@web/test-runner-playwright": "^0.11.0"
128+
"@web/test-runner-playwright": "^0.11.0",
129+
"http-proxy-middleware": "^2.0.7"
129130
},
130131
"lint-staged": {
131132
"*.{ts,js,html,css,json,webmanifest}": "prettier --write"

frontend/playwright.config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { defineConfig, devices } from "@playwright/test";
22

3-
/**
4-
* Read environment variables from file.
5-
* https://github.com/motdotla/dotenv
6-
*/
7-
// require('dotenv').config();
3+
if (!process.env.CI) {
4+
/**
5+
* Read environment variables from file.
6+
* https://github.com/motdotla/dotenv
7+
*/
8+
require("dotenv").config({
9+
path: ".env.local",
10+
});
11+
}
812

913
/**
1014
* See https://playwright.dev/docs/test-configuration.

frontend/sample.env.local

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
API_BASE_URL=
22
DOCS_URL=https://docs.browsertrix.com/
3+
E2E_USER_EMAIL=
4+
E2E_USER_PASSWORD=
35
GLITCHTIP_DSN=

frontend/scripts/serve.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Object.keys(devServer.proxy).forEach((path) => {
2727
app.use(
2828
path,
2929
createProxyMiddleware({
30-
target: devServer.proxy[path],
31-
changeOrigin: true,
30+
...devServer.proxy[path],
31+
followRedirects: true,
3232
}),
3333
);
3434
});

frontend/tests/login.spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ test("test", async ({ baseURL }) => {
1111
await page.waitForLoadState("load");
1212
await page.waitForSelector('input[name="username"]');
1313
await page.click('input[name="username"]');
14-
await page.fill('input[name="username"]', "dev@webrecorder.net");
14+
15+
const e2eEmail = process.env.E2E_USER_EMAIL;
16+
if (!e2eEmail) {
17+
throw new Error(
18+
"E2E_USER_EMAIL environment variable is not defined or null.",
19+
);
20+
}
21+
await page.fill('input[name="username"]', e2eEmail);
1522
await page.click('input[name="password"]');
16-
const devPassword = process.env.DEV_PASSWORD;
17-
if (!devPassword) {
23+
const e2ePassword = process.env.E2E_USER_PASSWORD;
24+
if (!e2ePassword) {
1825
throw new Error(
19-
"DEV_PASSWORD environment variable is not defined or null.",
26+
"E2E_USER_PASSWORD environment variable is not defined or null.",
2027
);
2128
}
22-
await page.fill('input[name="password"]', devPassword);
29+
await page.fill('input[name="password"]', e2ePassword);
2330
await page.click('sl-button:has-text("Log In")');
2431
} finally {
2532
await browser.close();

frontend/yarn.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)