Skip to content

Commit 080c2e5

Browse files
committed
feat(FR-1329): add a github action for regression test
1 parent 72f49f9 commit 080c2e5

File tree

5 files changed

+150
-8
lines changed

5 files changed

+150
-8
lines changed

.github/workflows/e2e-test.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# .github/workflows/playwright.yml
2+
name: Playwright Tests
3+
4+
on:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
runs-on: "ubuntu-latest"
10+
permissions:
11+
checks: write
12+
pull-requests: write
13+
contents: read
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
lts:
18+
- name: "main"
19+
apiEndpoint: "https://19d3c8.poc.isla-sorna.backend.ai/"
20+
- name: "v25.15" # Please update according to the latest LTS versions
21+
apiEndpoint: "https://19d3c8.poc.isla-sorna.backend.ai/"
22+
23+
name: E2E Playwright Tests for LTS ${{ matrix.lts.name }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
28+
- uses: pnpm/action-setup@v4
29+
name: Install pnpm
30+
with:
31+
version: latest
32+
run_install: false
33+
34+
- uses: actions/setup-node@v4
35+
name: Install Node.js
36+
with:
37+
node-version-file: ".nvmrc"
38+
cache: "pnpm"
39+
40+
- name: Get pnpm store directory
41+
shell: bash
42+
run: |
43+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
44+
45+
- uses: actions/cache@v4
46+
name: Setup pnpm cache
47+
with:
48+
path: ${{ env.STORE_PATH }}
49+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
50+
restore-keys: |
51+
${{ runner.os }}-pnpm-store-
52+
53+
- name: Install dependencies
54+
run: pnpm install
55+
56+
- name: Install Playwright Browsers
57+
run: pnpm exec playwright install --with-deps
58+
59+
- name: Copy config.toml.sample to config.toml
60+
run: |
61+
awk '
62+
/^[[:space:]]*$/ { next }
63+
/^\[.*\]$/ { if (n++) print ""; print; next }
64+
/^[[:space:]]*#[^=]/ { print; next }
65+
{
66+
line = $0
67+
sub(/#.*/, "", line)
68+
sub(/[[:space:]]+$/, "", line)
69+
if (line != "") print line
70+
}
71+
' config.toml.sample > config-cleaned.toml
72+
73+
- name: Inject apiEndpoint and allowChangeSigninMode into config.toml
74+
run: |
75+
EP="${{ matrix.lts.apiEndpoint }}"
76+
awk -v ep="$EP" '
77+
{
78+
if ($0 ~ /^apiEndpoint[[:space:]]*=/) {
79+
print "apiEndpoint = \"" ep "\""
80+
} else if ($0 ~ /^allowChangeSigninMode[[:space:]]*=/) {
81+
print "allowChangeSigninMode = true"
82+
} else {
83+
print
84+
}
85+
}
86+
' config-cleaned.toml > config.toml
87+
88+
# - name: Upload config.toml artifact
89+
# uses: actions/upload-artifact@v4
90+
# with:
91+
# name: config-toml-${{ matrix.lts.name }}
92+
# path: config.toml
93+
94+
- name: Build project
95+
run: pnpm run build
96+
97+
- name: Serve build at port 9081 (background)
98+
run: |
99+
pnpm server:p -s -l 9081 > /dev/null 2>&1 &
100+
echo "Waiting for server to start..."
101+
for i in {1..30}; do
102+
if curl -s http://127.0.0.1:9081 > /dev/null; then
103+
echo "Server is up!"
104+
break
105+
fi
106+
sleep 1
107+
done
108+
109+
- name: Run Playwright Tests
110+
run: pnpm playwright test
111+
112+
- name: Upload HTML report (on failure)
113+
if: failure()
114+
uses: actions/upload-artifact@v4
115+
with:
116+
name: playwright-report-${{ matrix.lts.name }}
117+
path: playwright-report/

e2e/utils/test-util.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ export const webuiEndpoint = 'http://127.0.0.1:9081';
55
export const webServerEndpoint = 'http://127.0.0.1:8090';
66
export const visualRegressionWebserverEndpoint = 'http://10.122.10.216:8090';
77

8+
export const changeSigninInMode = async (page: Page, mode: 'IAM' | 'ID') => {
9+
const button = page.locator('#change-signin-area button');
10+
if ((await button.textContent())?.includes(mode)) {
11+
await button.click();
12+
}
13+
};
14+
815
export async function login(
916
page: Page,
1017
username: string,
1118
password: string,
1219
endpoint: string,
1320
) {
1421
await page.goto(webuiEndpoint);
22+
await changeSigninInMode(page, 'ID');
1523
await page.getByLabel('Email or Username').fill(username);
1624
await page.getByRole('textbox', { name: 'Password' }).fill(password);
17-
await page.getByRole('textbox', { name: 'Endpoint' }).fill(endpoint);
25+
26+
const endpointInput = page.locator('#id_api_endpoint label');
27+
try {
28+
await endpointInput.waitFor({ state: 'visible', timeout: 1000 });
29+
await page.getByRole('textbox', { name: 'Endpoint' }).fill(endpoint);
30+
} catch (_e) {
31+
// Endpoint input not visible, skip filling it
32+
}
1833
await page.getByLabel('Login', { exact: true }).click();
1934
await page.waitForSelector('[data-testid="user-dropdown-button"]');
2035
}

playwright.config.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default defineConfig({
2121
/* Retry on CI only */
2222
retries: process.env.CI ? 2 : 0,
2323
/* Opt out of parallel tests on CI. */
24-
workers: process.env.CI ? 1 : undefined,
24+
// workers: process.env.CI ? 4 : undefined,
2525
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
2626
reporter: process.env.CI
2727
? [["html", { open: "never" }], ["github"]]
@@ -34,6 +34,7 @@ export default defineConfig({
3434
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3535
trace: "on-first-retry",
3636
},
37+
timeout: process.env.CI ? 10 * 1000 : undefined,
3738

3839
snapshotPathTemplate: `e2e/{testFileDir}/snapshot/{arg}{ext}`,
3940
/* Configure projects for major browsers */
@@ -74,9 +75,11 @@ export default defineConfig({
7475
// },
7576
],
7677
/* Run your local dev server before starting the tests */
77-
// webServer: {
78-
// command: 'npm run start',
79-
// url: 'http://127.0.0.1:3000',
80-
// reuseExistingServer: !process.env.CI,
81-
// },
78+
// webServer: process.env.CI
79+
// ? {
80+
// command: "pnpm run server:p -s -l 9081",
81+
// url: "http://127.0.0.1:9081",
82+
// timeout: 1000 * 60 * 5,
83+
// }
84+
// : undefined,
8285
});

src/components/backend-ai-login.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,7 @@ export default class BackendAILogin extends BackendAIPage {
21402140
? html`
21412141
<div
21422142
id="change-signin-area"
2143+
data-testid="change-login-mode-button"
21432144
class="vertical center-justified layout"
21442145
style="flex: 1; text-align: right;"
21452146
>

tsconfig.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,11 @@
2525
"lib": ["es6", "dom", "es2016", "es2017", "es2020"],
2626
"preserveWatchOutput": true
2727
},
28-
"include": ["src/components/*", "src/plugins/*", "src/reducers/*", "src/*"]
28+
"include": [
29+
"src/components/*",
30+
"src/plugins/*",
31+
"src/reducers/*",
32+
"src/*",
33+
"playwright.config.ts"
34+
]
2935
}

0 commit comments

Comments
 (0)