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

Migrate playwright tests to repo #77

Merged
merged 17 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"tsConfig": "tsconfig.spec.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
"scripts": [],
"exclude": ["playwright"]
}
},
"lint": {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"build": "ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test",
"lint": "ng lint"
"lint": "ng lint",
"playwright-install": "pip install -r requirements.txt && playwright install",
"playwright-test": "cd playwright/tests && pytest"
},
"private": true,
"dependencies": {
Expand Down
27 changes: 27 additions & 0 deletions playwright/.github/workflows/playwright.yml
mgriffin-scottlogic marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
mgriffin-scottlogic marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
branches: [ main, master ]
mgriffin-scottlogic marked this conversation as resolved.
Show resolved Hide resolved
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
mgriffin-scottlogic marked this conversation as resolved.
Show resolved Hide resolved
- 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
14 changes: 14 additions & 0 deletions playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
*.pyc
*.pyo
# Ignore folders generated by Bundler
.bundle/
vendor/
# Ignore Mac DS_Store files
.DS_Store
**/.DS_Store
# Ignore .vscode settings folder
.vscode/
84 changes: 84 additions & 0 deletions playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Testing of Carbon Estimator using Playwright and Python



## Python
Python homepage
https://www.python.org/downloads/release/python-3110/

## Playwright
Installation of Playwright: https://playwright.dev/python/docs/intro

Install the Pytest plugin:
`pip install pytest-playwright`

Install the required browsers:
`playwright install`


Playwright demo tests: https://playwright.dev/python/docs/writing-tests


## Playwright - Run tests
Running tests: https://playwright.dev/python/docs/running-tests

To run a test:
Tests can be run in the Command Prompt terminal or using a code editor (for instance - Visual Studio Code).

Visual Studio Code download:
https://code.visualstudio.com/

Ensure you are pointing to the folder containing the test cases.
Example: `C:\Development\Technology-Carbon-Standard\tests_tcs>`

To run a test in `C:\Development\Technology-Carbon-Standard\tests_tcs>`:

Test name must begin with `test`, must be prefixed by the command `pytest` and must be suffixed by `.py`

Example command: `pytest test_2_EstTool_HappyPath_Default.py`

Line should look like: `C:\Development\Technology-Carbon-Standard\tests_tcs>pytest test_2_EstTool_HappyPath_Default.py`

If successful, output in terminal window will be along lines of `1 passed in 4.23s`

Test name example will have a green full stop `.` suffix:
Example: `test_2_EstTool_HappyPath_Default.py .`

If test fails, output in terminal window will be along lines `1 failed in 1.38s`

Test name example will have `F` suffix:
Example: `test_2_EstTool_HappyPath_Default.py F`

Cause of test failure is output in the same terminal window

Tests are automatically “headless”, meaning no browser window will be opened while running the tests and only results (Pass or Fail) will be seen in the terminal. However, you can run tests in headed mode by using the `--headed`
and the browser window will open.

Example: `pytest test_2_EstTool_HappyPath_Default.py --headed`

If you would like to view test flow in browser as it runs step by step but find that tests run too quick (browser window opens and closes too quickly) you can slow test down by adding `--slowmo`

Example: `pytest test_2_EstTool_HappyPath_Default.py --headed --slowmo 1000` (or 2000)

Tests can be run in different browsers (Use `chromium` for Chrome, `firefox` for Firefox & `webkit` for Safari). The following test will run on firefox and browser window will be open.

Example: `pytest test_2_EstTool_HappyPath_Default.py --browser=firefox --headed`

Note: All tests are pointing to `http://localhost:4200/`, if there is an issue with this (possibly 4200 may already be in use) then you may be directed to a different url, example `http://localhost:5600/`
If this is the case then then the code within each individual test to be run may need updated to match with localhost address otherwise the test(s) will fail. No global file was available to cover this scenario.
mgriffin-scottlogic marked this conversation as resolved.
Show resolved Hide resolved

# Running Carbon Estimator Tool

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 16.1.4.

Run `npm install` to get the most recent dependencies

## Development server

Run `ng serve` or `npm run start` for a dev server.

Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.

As mentioned previously, if directed to `http://localhost:5600/` instead of `http://localhost:4200/` then will have to update tests to match


68 changes: 68 additions & 0 deletions playwright/playwright-report/index.html
mgriffin-scottlogic marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

Loading