From 5714409f76f78baff44599acf7296f1d2de1e5eb Mon Sep 17 00:00:00 2001 From: ChloeLin Date: Wed, 10 Jan 2024 17:50:39 +0800 Subject: [PATCH 1/5] add playwright, and some tests --- .github/workflows/playwright.yml | 27 +++++++++++ .gitignore | 4 ++ package.json | 1 + playwright.config.js | 79 ++++++++++++++++++++++++++++++++ tests/example.spec.js | 19 ++++++++ yarn.lock | 55 ++++++++++++++++++++++ 6 files changed, 185 insertions(+) create mode 100644 .github/workflows/playwright.yml create mode 100644 playwright.config.js create mode 100644 tests/example.spec.js diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 000000000..fc61546e8 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,27 @@ +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm install -g yarn && yarn + - name: Install Playwright Browsers + run: yarn playwright install --with-deps + - name: Run Playwright tests + run: yarn playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.gitignore b/.gitignore index 195d0cc42..ce023a849 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ build /test-results/ /playwright-report/ /playwright/.cache/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/package.json b/package.json index 18c3abd5a..ec0368144 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "@fortawesome/free-brands-svg-icons": "^6.4.2", "@fortawesome/free-solid-svg-icons": "^6.4.2", "@fortawesome/react-fontawesome": "^0.2.0", + "@playwright/test": "^1.40.1", "@types/node": "^20.8.7", "eslint": "^8.53.0", "eslint-plugin-jsx-a11y": "^6.8.0", diff --git a/playwright.config.js b/playwright.config.js new file mode 100644 index 000000000..b15af2e18 --- /dev/null +++ b/playwright.config.js @@ -0,0 +1,79 @@ +// @ts-check +const { defineConfig, devices } = require('@playwright/test'); + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// require('dotenv').config(); + +/** + * @see https://playwright.dev/docs/test-configuration + */ +module.exports = defineConfig({ + testDir: './tests', + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + // baseURL: 'http://127.0.0.1:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'firefox', + use: { ...devices['Desktop Firefox'] }, + }, + + { + name: 'webkit', + use: { ...devices['Desktop Safari'] }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); + diff --git a/tests/example.spec.js b/tests/example.spec.js new file mode 100644 index 000000000..40eddb861 --- /dev/null +++ b/tests/example.spec.js @@ -0,0 +1,19 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); + +test('has title', async ({ page }) => { + await page.goto('https://playwright.dev/'); + + // Expect a title "to contain" a substring. + await expect(page).toHaveTitle(/Playwright/); +}); + +test('get started link', async ({ page }) => { + await page.goto('https://playwright.dev/'); + + // Click the get started link. + await page.getByRole('link', { name: 'Get started' }).click(); + + // Expects page to have a heading with the name of Installation. + await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); +}); diff --git a/yarn.lock b/yarn.lock index ec0cd31ba..f30ce55ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4161,6 +4161,17 @@ __metadata: languageName: node linkType: hard +"@playwright/test@npm:^1.40.1": + version: 1.40.1 + resolution: "@playwright/test@npm:1.40.1" + dependencies: + playwright: "npm:1.40.1" + bin: + playwright: cli.js + checksum: 1edbc9659fb6a9c5299cacd9a0c7d3fdc88939036642d8f367e13d267d808ae3f88ca9d00e9981e3bcd5f584ccefba38d24eda6b23d27895908f203dc35f339e + languageName: node + linkType: hard + "@pmmmwh/react-refresh-webpack-plugin@npm:^0.5.10": version: 0.5.11 resolution: "@pmmmwh/react-refresh-webpack-plugin@npm:0.5.11" @@ -5332,6 +5343,7 @@ __metadata: "@fortawesome/free-solid-svg-icons": "npm:^6.4.2" "@fortawesome/react-fontawesome": "npm:^0.2.0" "@microsoft/applicationinsights-web": "npm:^3.0.3" + "@playwright/test": "npm:^1.40.1" "@raae/gatsby-remark-oembed": "npm:^0.3.3" "@types/node": "npm:^20.8.7" algoliasearch: "npm:^4.20.0" @@ -11504,6 +11516,16 @@ __metadata: languageName: node linkType: hard +"fsevents@npm:2.3.2": + version: 2.3.2 + resolution: "fsevents@npm:2.3.2" + dependencies: + node-gyp: "npm:latest" + checksum: be78a3efa3e181cda3cf7a4637cb527bcebb0bd0ea0440105a3bb45b86f9245b307dc10a2507e8f4498a7d4ec349d1910f4d73e4d4495b16103106e07eee735b + conditions: os=darwin + languageName: node + linkType: hard + "fsevents@npm:~2.3.2": version: 2.3.3 resolution: "fsevents@npm:2.3.3" @@ -11514,6 +11536,15 @@ __metadata: languageName: node linkType: hard +"fsevents@patch:fsevents@npm%3A2.3.2#optional!builtin": + version: 2.3.2 + resolution: "fsevents@patch:fsevents@npm%3A2.3.2#optional!builtin::version=2.3.2&hash=df0bf1" + dependencies: + node-gyp: "npm:latest" + conditions: os=darwin + languageName: node + linkType: hard + "fsevents@patch:fsevents@npm%3A~2.3.2#optional!builtin": version: 2.3.3 resolution: "fsevents@patch:fsevents@npm%3A2.3.3#optional!builtin::version=2.3.3&hash=df0bf1" @@ -18256,6 +18287,30 @@ __metadata: languageName: node linkType: hard +"playwright-core@npm:1.40.1": + version: 1.40.1 + resolution: "playwright-core@npm:1.40.1" + bin: + playwright-core: cli.js + checksum: 56c283012974982313a6ae583b975ee4af76d52059fb9a25d9cc616a11224685ec64682b391910c795d2b12d2ab5c7eec31124722c75c0b1703a76ac9b6fd1c2 + languageName: node + linkType: hard + +"playwright@npm:1.40.1": + version: 1.40.1 + resolution: "playwright@npm:1.40.1" + dependencies: + fsevents: "npm:2.3.2" + playwright-core: "npm:1.40.1" + dependenciesMeta: + fsevents: + optional: true + bin: + playwright: cli.js + checksum: 5dae164d1f69162da8d7eee52da651296fb885c76a8b36049f216975c751a0a826ff05795a1c0902dc0bd193fe606ae17d5def655f4cbcccb8d8b71afb74b950 + languageName: node + linkType: hard + "plist@npm:^3.0.1": version: 3.1.0 resolution: "plist@npm:3.1.0" From aabfe423844c985cc225358aef40938931606c1a Mon Sep 17 00:00:00 2001 From: ChloeLin Date: Thu, 11 Jan 2024 14:40:24 +0800 Subject: [PATCH 2/5] change timeout to 60s --- playwright.config.js | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/playwright.config.js b/playwright.config.js index b15af2e18..c5b14f09a 100644 --- a/playwright.config.js +++ b/playwright.config.js @@ -12,7 +12,6 @@ const { defineConfig, devices } = require('@playwright/test'); */ module.exports = defineConfig({ testDir: './tests', - /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, @@ -22,16 +21,12 @@ module.exports = defineConfig({ workers: process.env.CI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: 'html', - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + timeout: 5 * 60 * 1000, use: { - /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://127.0.0.1:3000', - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', }, - /* Configure projects for major browsers */ projects: [ { name: 'chromium', @@ -47,33 +42,5 @@ module.exports = defineConfig({ name: 'webkit', use: { ...devices['Desktop Safari'] }, }, - - /* Test against mobile viewports. */ - // { - // name: 'Mobile Chrome', - // use: { ...devices['Pixel 5'] }, - // }, - // { - // name: 'Mobile Safari', - // use: { ...devices['iPhone 12'] }, - // }, - - /* Test against branded browsers. */ - // { - // name: 'Microsoft Edge', - // use: { ...devices['Desktop Edge'], channel: 'msedge' }, - // }, - // { - // name: 'Google Chrome', - // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, - // }, ], - - /* Run your local dev server before starting the tests */ - // webServer: { - // command: 'npm run start', - // url: 'http://127.0.0.1:3000', - // reuseExistingServer: !process.env.CI, - // }, }); - From 22a3e9bf9c48dfe277136f252e88a18543241b55 Mon Sep 17 00:00:00 2001 From: ChloeLin Date: Thu, 11 Jan 2024 16:16:13 +0800 Subject: [PATCH 3/5] add test to check megadata in a random rule --- tests/megadata.spec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/megadata.spec.js diff --git a/tests/megadata.spec.js b/tests/megadata.spec.js new file mode 100644 index 000000000..1c8f7648f --- /dev/null +++ b/tests/megadata.spec.js @@ -0,0 +1,25 @@ +// @ts-check +const { test, expect } = require('@playwright/test'); + +const baseurl = 'https://ssw.com.au/rules'; + +test('should have history.json', async ({ request }) => { + const response = await request.get(`${baseurl}/history.json`); + expect(response.status()).toBe(200); +}); + +test('should have megadata', async ({ page }) => { + await page.goto('https://ssw.com.au/rules/latest-rules/?size=50'); + + let randomNum = Math.floor(Math.random() * 50); + + const ruleLink = await page + .locator('.cat-grid-container') + .getByRole('link') + .nth(randomNum); + + await ruleLink.click(); + + const locator = page.locator('.history'); + await expect(locator).toContainText('See history'); +}); From e3bb28324381698f1b8b870f53c6c910fb10dfc7 Mon Sep 17 00:00:00 2001 From: ChloeLin Date: Thu, 11 Jan 2024 16:37:13 +0800 Subject: [PATCH 4/5] delete example --- tests/example.spec.js | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 tests/example.spec.js diff --git a/tests/example.spec.js b/tests/example.spec.js deleted file mode 100644 index 40eddb861..000000000 --- a/tests/example.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -// @ts-check -const { test, expect } = require('@playwright/test'); - -test('has title', async ({ page }) => { - await page.goto('https://playwright.dev/'); - - // Expect a title "to contain" a substring. - await expect(page).toHaveTitle(/Playwright/); -}); - -test('get started link', async ({ page }) => { - await page.goto('https://playwright.dev/'); - - // Click the get started link. - await page.getByRole('link', { name: 'Get started' }).click(); - - // Expects page to have a heading with the name of Installation. - await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); -}); From 77c8122c20a179e3ac67678d48c1b5e69538def9 Mon Sep 17 00:00:00 2001 From: ChloeLin Date: Thu, 11 Jan 2024 16:44:08 +0800 Subject: [PATCH 5/5] update yaml --- .github/workflows/playwright.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index fc61546e8..cdb65137e 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,9 +1,13 @@ name: Playwright Tests + on: - push: - branches: [ main, master ] pull_request: - branches: [ main, master ] + branches: + include: + - release/* + exclude: + - main + jobs: test: timeout-minutes: 60