Skip to content

Commit 866c5ce

Browse files
committed
fix: Removed unneeded e2e tests + improved GH action
1 parent 7334450 commit 866c5ce

File tree

2 files changed

+55
-140
lines changed

2 files changed

+55
-140
lines changed

.github/workflows/playwright.yml

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
1-
name: UI validation on prod
1+
name: Running Playwright test on UI
22
on:
3-
workflow_dispatch:
3+
push:
4+
paths:
5+
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
6+
- 'content/nginxaas-azure/billing/usage-and-cost-estimator.md'
7+
pull_request:
8+
paths:
9+
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
10+
- 'content/nginxaas-azure/billing/usage-and-cost-estimator.md'
411

512
jobs:
13+
get-playwright-version:
14+
name: Get Playwright Version
15+
runs-on: ubuntu-latest
16+
outputs:
17+
version: ${{ steps.get-playwright-version.outputs.version }}
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
21+
- name: Get version from package.json
22+
id: get-playwright-version
23+
run: |
24+
cd tests
25+
version=$(jq -r '.devDependencies["@playwright/test"] // .dependencies["@playwright/test"]' package.json)
26+
test -n "$version" || { echo "No @playwright/test version found in package.json"; exit 1; }
27+
echo "version=$version" >> $GITHUB_OUTPUT
28+
echo "Version: " $version
629
run-playwright-tests:
30+
name: Run Playwright
31+
needs: get-playwright-version
732
runs-on: ubuntu-latest
33+
container:
34+
image: mcr.microsoft.com/playwright:v${{needs.get-playwright-version.outputs.version}}-jammy
835
steps:
9-
- uses: actions/checkout@v4
10-
- uses: actions/setup-node@v6
36+
- name: Checkout code
37+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
38+
- name: Setup Hugo
39+
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3.0.0
1140
with:
12-
node-version: lts/*
41+
hugo-version: '0.147.8'
42+
extended: true
43+
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 #v6.0.0
44+
with:
45+
go-version: '1.24.6'
1346
- name: Install dependencies
1447
run: npm ci
15-
- name: Install Playwright Browsers
16-
run: npx playwright install --with-deps
1748
- name: Run Playwright tests
18-
run: npx playwright test --retries=2
19-
- uses: actions/upload-artifact@v6
20-
if: ${{ !cancelled() }}
49+
id: test-ui
50+
# Check done to set the home variable. Workaround as browser is unable to launch if the $HOME folder isn't owned by the current user.
51+
if: ${{ runner.os == 'Linux' }}
52+
env:
53+
HOME: /root
54+
run: |
55+
git config --global --add safe.directory /__w/nginx-hugo-theme/nginx-hugo-theme
56+
cd tests && npx playwright test | tee output.log
57+
if grep -q "failed" output.log; then
58+
echo "Playwright tests failed. Please view the Playwright report to see full error."
59+
exit 1
60+
fi
61+
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
62+
id: artifact-upload
63+
if: ${{ !cancelled() && failure() && steps.test-ui.conclusion == 'failure' }}
2164
with:
2265
name: playwright-report
2366
path: tests/playwright-report/
24-
retention-days: 30
25-
- uses: actions/upload-artifact@v6
26-
if: ${{ !cancelled() }}
27-
with:
28-
name: test-results
29-
path: tests/test-results/
30-
retention-days: 30
67+
retention-days: 3

tests/n4a-calculator.spec.ts

Lines changed: 1 addition & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,6 @@
11
import { expect, test } from "@playwright/test";
22
import { handleConsentPopup, waitFor } from "./util";
33

4-
/**
5-
* Changes the input for a given form section by updating the value in the input with the given value multiplier, and checks if the given value locator changes.
6-
* Sometimes it shouldn't, so use 'shouldValueChange' to denote if a change is expected or not.
7-
*
8-
* @param page
9-
* @param formSection
10-
* @param value
11-
* @param valueMultiplier
12-
* @param shouldValueChange
13-
*/
14-
async function updateInputs(page, formSection, value, valueMultiplier = 3, shouldValueChange = true) {
15-
const inputs = await (formSection.locator("input")).all();
16-
const oldNcuEstimate = await value.textContent();
17-
18-
for(let i = 0; i < inputs.length; i++) {
19-
const input = inputs.at(i);
20-
const type = await input.getAttribute("type");
21-
if(input && type === "number") {
22-
const value = Number(await input.inputValue());
23-
const newValue = value + (value * valueMultiplier); // Increase by some significant value
24-
await input.fill(newValue.toString());
25-
await page.keyboard.press('Enter');
26-
}
27-
else if(type === "checkbox") {
28-
await input.check();
29-
}
30-
31-
const newNcuEstimate = await value.textContent();
32-
if(shouldValueChange) {
33-
expect(newNcuEstimate).not.toBe(oldNcuEstimate);
34-
}
35-
else {
36-
expect(newNcuEstimate).toBe(oldNcuEstimate)
37-
}
38-
}
39-
}
40-
41-
/**
42-
* Returns a random number between the given min and max, inclusive.
43-
*
44-
* @param min
45-
* @param max
46-
* @returns
47-
*/
48-
function getRandomNumber(min, max) {
49-
// Enforce to be integer
50-
min = Math.ceil(min);
51-
max = Math.floor(max);
52-
return Math.floor(Math.random() * (max - min + 1)) + min;
53-
}
54-
554
test.describe("Testing for N4A calculator page", () => {
565
test.beforeEach(async ({ page }) => {
576
await page.goto("/nginxaas/azure/billing/usage-and-cost-estimator/");
@@ -69,82 +18,11 @@ test.describe("Testing for N4A calculator page", () => {
6918

7019
test("calculator values render", async ({ page }) => {
7120
// Conjunction - If outputs are rendered, it is safe to say the inputs are rendered.
21+
// NOT testing changing numbers will impact the total values as that should be the job of unit tests. This is just a smoke tests.
7222
const ncuEstimateValue = page.getByTestId("ncuEstimateValue");
7323
const totalValue = page.getByTestId("total-value");
7424

7525
expect(await ncuEstimateValue.textContent()).toBeTruthy();
7626
expect(await totalValue.textContent()).toBeTruthy();
7727
});
78-
79-
test("inputs from 'Estimate NCU Usage' section change NCU Needed (happy)", async ({ page }) => {
80-
const totalValue = page.getByTestId("total-value");
81-
const oldTotalValue = await totalValue.textContent();
82-
const ncuEstimateValue = page.getByTestId("ncuEstimateValue");
83-
const formSectionEstimateNCU = page.getByTestId("form-section-content-estimateNCUUsage");
84-
85-
// Inputs from NCU box should adjust estimate
86-
await updateInputs(page, formSectionEstimateNCU, ncuEstimateValue, 80);
87-
88-
// Check that total value changes
89-
// Safe to say, if estimate NCU changes, so will the total monthly payment
90-
const newTotalValue = await totalValue.textContent();
91-
expect(newTotalValue).not.toBe(oldTotalValue);
92-
93-
});
94-
95-
test("inputs from 'Estimate NCU Usage' section change NCU Needed (unhappy 1)", async ({ page }) => {
96-
const totalValue = page.getByTestId("total-value");
97-
const oldTotalValue = await totalValue.textContent();
98-
const ncuEstimateValue = page.getByTestId("ncuEstimateValue");
99-
const formSectionEstimateNCU = page.getByTestId("form-section-content-estimateNCUUsage");
100-
101-
// Inputs from NCU box should adjust estimate
102-
await updateInputs(page, formSectionEstimateNCU, ncuEstimateValue, 0.1, false);
103-
104-
// Check that total value doesn't changes
105-
const newTotalValue = await totalValue.textContent();
106-
expect(newTotalValue).toBe(oldTotalValue);
107-
});
108-
109-
test("inputs from 'Estimate NCU Usage' section change NCU Needed (unhappy 2)", async ({ page }) => {
110-
const totalValue = page.getByTestId("total-value");
111-
const oldTotalValue = await totalValue.textContent();
112-
const ncuEstimateValue = page.getByTestId("ncuEstimateValue");
113-
const formSectionEstimateNCU = page.getByTestId("form-section-content-estimateNCUUsage");
114-
115-
// Inputs from NCU box should adjust estimate
116-
await updateInputs(page, formSectionEstimateNCU, ncuEstimateValue, -0.1, false);
117-
118-
// Check that total value doesn't changes
119-
const newTotalValue = await totalValue.textContent();
120-
expect(newTotalValue).toBe(oldTotalValue);
121-
});
122-
123-
test("inputs from 'Estimate Monthly Cost' section change Total Monthly Payment", async ({ page }) => {
124-
const totalValue = page.getByTestId("total-value");
125-
const formSectionMonthlyCost = page.getByTestId("form-section-content-estimateMonthlyCost");
126-
127-
await updateInputs(page, formSectionMonthlyCost, totalValue);
128-
});
129-
130-
test("'Listen Ports' input conditionally changes Total Monthly Payment", async({ page }) => {
131-
const listenPorts = page.getByTestId("input-numListenPorts");
132-
const totalValue = page.getByTestId("total-value");
133-
const oldTotalValue = await totalValue.textContent();
134-
const randomMaxValue = getRandomNumber(5, 10); // Smaller max for performance reasons.
135-
136-
for(let i = 1; i <= randomMaxValue; i++) {
137-
await listenPorts.fill(i.toString());
138-
await page.keyboard.press('Enter');
139-
140-
// First 5 are included
141-
const newTotalValue = await totalValue.textContent();
142-
if(i <= 5) {
143-
expect(newTotalValue).toBe(oldTotalValue);
144-
}
145-
else {
146-
expect(newTotalValue).not.toBe(oldTotalValue);
147-
}
148-
}
149-
});
15028
});

0 commit comments

Comments
 (0)