From 7b58fdb621d390bcfc9635346b4bdec1efd37db0 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Thu, 13 Jun 2024 15:27:43 +0100 Subject: [PATCH 1/9] Move playwright workflow Update with local actions and Python specific requirements --- .github/workflows/playwright.yml | 28 +++++++++++++++++++++ playwright/.github/workflows/playwright.yml | 27 -------------------- 2 files changed, 28 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/playwright.yml delete mode 100644 playwright/.github/workflows/playwright.yml diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 00000000..0b17e594 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,28 @@ +name: Playwright Tests +on: + push: + branches: [ main ] + pull_request: +jobs: + test: + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up environment + uses: ./.github/actions/set-up-environment + - name: Setup Python + uses: actions/setup-python@v5.1.0 + with: + python-version: '3.11' + - name: Install Playwright Dependencies + run: npm run playwright-install + - name: Run Playwright tests + run: npm run playwright-test + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-report + path: playwright/playwright-report/ + retention-days: 30 diff --git a/playwright/.github/workflows/playwright.yml b/playwright/.github/workflows/playwright.yml deleted file mode 100644 index 467190be..00000000 --- a/playwright/.github/workflows/playwright.yml +++ /dev/null @@ -1,27 +0,0 @@ -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@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 From 26434d1a20c4b472bc87f228ad5b43f96a4fac88 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Thu, 13 Jun 2024 15:42:33 +0100 Subject: [PATCH 2/9] CI Install may need dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7d677bb0..97fe2f98 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "watch": "ng build --watch --configuration development", "test": "ng test", "lint": "ng lint", - "playwright-install": "pip install -r requirements.txt && playwright install", + "playwright-install": "pip install -r requirements.txt && playwright install --with-deps", "playwright-test": "cd playwright/tests && pytest" }, "private": true, From 1b084cd14dce782e022505b0972ae5ad82dc35ee Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Fri, 14 Jun 2024 13:52:13 +0100 Subject: [PATCH 3/9] Use cross platform method of running npm Ensure server is terminated on interrupt --- playwright/tests/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/playwright/tests/conftest.py b/playwright/tests/conftest.py index a1ce0a81..66a3c25a 100644 --- a/playwright/tests/conftest.py +++ b/playwright/tests/conftest.py @@ -1,4 +1,5 @@ import pytest +import shutil from xprocess import ProcessStarter @pytest.fixture(autouse=True, scope="session") @@ -8,7 +9,9 @@ class Starter(ProcessStarter): pattern = "Application bundle generation complete." # command to start process - args = ['sh', 'npm', 'start'] + args = [shutil.which('npm'), 'start'] + + terminate_on_interrupt = True # ensure process is running and return its logfile logfile = xprocess.ensure("estimator", Starter) From 4949da1d53440410068132e813428487f0d45bfa Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 09:20:05 +0100 Subject: [PATCH 4/9] Run playwright on successful completion of PR Workflow and allow manual trigger --- .github/workflows/playwright.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 0b17e594..30ff50b4 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -2,11 +2,15 @@ name: Playwright Tests on: push: branches: [ main ] - pull_request: + workflow_run: + workflows: ['PR Workflow'] + types: [completed] + workflow_dispatch: jobs: test: timeout-minutes: 10 runs-on: ubuntu-latest + if: ${{ github.event.workflow_run == null || github.event.workflow_run.conclusion != 'failure' }} steps: - name: Check out code uses: actions/checkout@v4 From 09317b8970ab93c148f8518af326692b121072aa Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 09:46:13 +0100 Subject: [PATCH 5/9] Add Playwright into its own action that can run separately or in pull request --- .github/actions/run-playwright/action.yml | 21 +++++++++++++++++++++ .github/workflows/playwright.yml | 20 ++------------------ .github/workflows/pull-request.yml | 10 ++++++++++ 3 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 .github/actions/run-playwright/action.yml diff --git a/.github/actions/run-playwright/action.yml b/.github/actions/run-playwright/action.yml new file mode 100644 index 00000000..68cc8df2 --- /dev/null +++ b/.github/actions/run-playwright/action.yml @@ -0,0 +1,21 @@ +name: 'Run Playwright' +description: 'Sets up Python, installs dependencies and runs playwright tests' +runs: + using: 'composite' + steps: + - name: Setup Python + uses: actions/setup-python@v5.1.0 + with: + python-version: '3.11' + - name: Install Playwright Dependencies + run: npm run playwright-install + shell: bash + - name: Run Playwright tests + run: npm run playwright-test + shell: bash + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-report + path: playwright/playwright-report/ + retention-days: 30 \ No newline at end of file diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 30ff50b4..c519ab48 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -2,31 +2,15 @@ name: Playwright Tests on: push: branches: [ main ] - workflow_run: - workflows: ['PR Workflow'] - types: [completed] workflow_dispatch: jobs: test: timeout-minutes: 10 runs-on: ubuntu-latest - if: ${{ github.event.workflow_run == null || github.event.workflow_run.conclusion != 'failure' }} steps: - name: Check out code uses: actions/checkout@v4 - name: Set up environment uses: ./.github/actions/set-up-environment - - name: Setup Python - uses: actions/setup-python@v5.1.0 - with: - python-version: '3.11' - - name: Install Playwright Dependencies - run: npm run playwright-install - - name: Run Playwright tests - run: npm run playwright-test - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright/playwright-report/ - retention-days: 30 + - name: Run Playwright + uses: ./.github/actions/run-playwright diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 65b245fd..960f65ec 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -21,3 +21,13 @@ jobs: uses: ./.github/actions/set-up-environment - name: Run tests run: npm test + playwright_tests: + needs: unit_tests + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Set up environment + uses: ./.github/actions/set-up-environment + - name: Run Playwright + uses: ./.github/actions/run-playwright From 58d2f7a4c976a4edced32e4445a27d3830dcf272 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 11:43:29 +0100 Subject: [PATCH 6/9] Fix up a couple more errors --- .../tests/test_0_TrialTest_HappyPath.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/playwright/tests/test_0_TrialTest_HappyPath.py b/playwright/tests/test_0_TrialTest_HappyPath.py index e062d471..9a8709e7 100644 --- a/playwright/tests/test_0_TrialTest_HappyPath.py +++ b/playwright/tests/test_0_TrialTest_HappyPath.py @@ -15,27 +15,23 @@ def test_example(page: Page) -> None: page.get_by_text("Laptops 50%").click() expect(page.get_by_role("heading", name="On-Premise Servers")).to_be_visible() expect(page.get_by_label("Number of Servers:")).to_have_value("10"); - expect(page.get_by_label("Where are they primarily")).to_have_value("global"); + expect(page.get_by_label("Where are they primarily")).to_have_value("WORLD"); expect(page.get_by_role("heading", name="Cloud Services")).to_be_visible() expect(page.get_by_text("Cloud 50%")).to_be_visible() - expect(page.get_by_text("On-prem 50%")).to_be_visible() - expect(page.get_by_label("Where are your cloud servers")).to_have_value("global"); + expect(page.get_by_text("On-premise 50%")).to_be_visible() + expect(page.get_by_label("Where are your cloud servers")).to_have_value("WORLD"); expect(page.get_by_label("What is your monthly cloud")).to_have_value("0: Object"); expect(page.get_by_role("heading", name="Users")).to_be_visible() - expect(page.get_by_text("Where are your users")).to_be_visible() - expect(page.get_by_label("Where are your users")).to_have_value("global"); + expect(page.get_by_text("Where are your end-users")).to_be_visible() + expect(page.get_by_label("Where are your end-users")).to_have_value("WORLD"); expect(page.get_by_text("How many monthly active users")).to_be_visible() expect(page.get_by_label("How many monthly active users")).to_have_value("100"); expect(page.get_by_text("Mobile 50%")).to_be_visible() expect(page.get_by_text("Computer 50%")).to_be_visible() - expect(page.get_by_text("What's the purpose of your")).to_be_visible() - expect(page.get_by_label("What's the purpose of your")).to_have_value("average"); + expect(page.get_by_text("What's the primary purpose of your")).to_be_visible() + expect(page.get_by_label("What's the primary purpose of your")).to_have_value("average"); page.get_by_role("button", name="Calculate").click() - expect(page.get_by_text("Upstream Emissions:")).to_be_visible() - expect(page.get_by_text("28%")).to_be_visible() - expect(page.get_by_text("Indirect Emissions:")).to_be_visible() - expect(page.get_by_text("0%", exact=True)).to_be_visible() - expect(page.get_by_text("Direct Emissions:", exact=True)).to_be_visible() - expect(page.get_by_text("71%")).to_be_visible() - expect(page.get_by_text("Downstream Emissions:")).to_be_visible() - expect(page.get_by_text("1%", exact=True)).to_be_visible() + expect(page.locator("foreignobject")).to_contain_text("Upstream Emissions - 33%") + expect(page.locator("foreignobject")).to_contain_text("Direct Emissions - 65%") + expect(page.locator("foreignobject")).to_contain_text("Indirect Emissions - 1%") + expect(page.locator("foreignobject")).to_contain_text("Downstream Emissions - <1%") From d4741d78e5b0fbb5af063bd8a3d3ede202c05c0e Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 11:51:39 +0100 Subject: [PATCH 7/9] Add a shorter timeout for server startup --- playwright/tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/playwright/tests/conftest.py b/playwright/tests/conftest.py index 66a3c25a..8af17bb6 100644 --- a/playwright/tests/conftest.py +++ b/playwright/tests/conftest.py @@ -13,6 +13,8 @@ class Starter(ProcessStarter): terminate_on_interrupt = True + timeout = 20 + # ensure process is running and return its logfile logfile = xprocess.ensure("estimator", Starter) From c9499599a5f212eab0a4e02cfa8afa80b9901dc8 Mon Sep 17 00:00:00 2001 From: Matthew Griffin <117279304+mgriffin-scottlogic@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:23:55 +0100 Subject: [PATCH 8/9] Run playwright in parallel with unit tests Co-authored-by: jantoun-scottlogic <110816538+jantoun-scottlogic@users.noreply.github.com> --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 960f65ec..6ddc6563 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -22,7 +22,7 @@ jobs: - name: Run tests run: npm test playwright_tests: - needs: unit_tests + needs: build runs-on: ubuntu-latest steps: - name: Check out code From 7f7da4668a96fa0c0f09bfd0438dc68f62fdeb7a Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 17 Jun 2024 15:45:02 +0100 Subject: [PATCH 9/9] Remove artifact upload step until we have reports generated by Playwright --- .github/actions/run-playwright/action.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/actions/run-playwright/action.yml b/.github/actions/run-playwright/action.yml index 68cc8df2..3f3f7b1a 100644 --- a/.github/actions/run-playwright/action.yml +++ b/.github/actions/run-playwright/action.yml @@ -13,9 +13,3 @@ runs: - name: Run Playwright tests run: npm run playwright-test shell: bash - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright/playwright-report/ - retention-days: 30 \ No newline at end of file