Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFD-114 - Add playwright tests into automated testing #79

Merged
merged 9 commits into from
Jun 21, 2024
21 changes: 21 additions & 0 deletions .github/actions/run-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/
jantoun-scottlogic marked this conversation as resolved.
Show resolved Hide resolved
retention-days: 30
16 changes: 16 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Playwright Tests
on:
push:
branches: [ main ]
workflow_dispatch:
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: Run Playwright
uses: ./.github/actions/run-playwright
10 changes: 10 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,13 @@ jobs:
uses: ./.github/actions/set-up-environment
- name: Run tests
run: npm test
playwright_tests:
needs: build
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 0 additions & 27 deletions playwright/.github/workflows/playwright.yml

This file was deleted.

7 changes: 6 additions & 1 deletion playwright/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import shutil
from xprocess import ProcessStarter

@pytest.fixture(autouse=True, scope="session")
Expand All @@ -8,7 +9,11 @@ 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

timeout = 20

# ensure process is running and return its logfile
logfile = xprocess.ensure("estimator", Starter)
Expand Down
26 changes: 11 additions & 15 deletions playwright/tests/test_0_TrialTest_HappyPath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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%")
Loading