-
Notifications
You must be signed in to change notification settings - Fork 1
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
Configure E2E testing package #1493
Changes from 26 commits
23a4349
60b7b59
7ba82a6
a7e3fbd
9ccd635
13a6781
02fe763
d02eac4
f2e12fe
dd674ee
d216722
2fde234
3c56819
46beaae
82051b4
ecdcc9e
ddde7ae
0c1dabd
55ee278
a578144
352b23f
d67686d
28d1696
66f1f19
76a41cc
cf98b33
d17ead4
b97c5ab
8ef944d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Editor configuration, see https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.ts] | ||
quote_type = single | ||
|
||
[*.md] | ||
max_line_length = off | ||
trim_trailing_whitespace = false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
test-results/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# End-to-End Testing | ||
|
||
- [Writing Tests](#writing-tests) | ||
- [Running Tests](#running-tests) | ||
- [Local Setup](#local-setup) | ||
- [Installation](#installation) | ||
- [Configure secrets](#configure-secrets) | ||
|
||
E2E test automation is implemented using the [Playwright](https://playwright.dev/). | ||
|
||
> [!WARNING] | ||
> When writing tests, make sure they do not contain any credentials _before_ committing to the repo. | ||
|
||
## Writing Tests | ||
|
||
- Write tests for a given project, i.e., tests for the portal go in `/e2e/tests/portal`. | ||
|
||
## Running Tests | ||
|
||
To run tests: | ||
|
||
```bash | ||
$ npx playwright test | ||
``` | ||
|
||
To run tests just for a specific project: | ||
|
||
```bash | ||
$ npx playwright test --project=[portal] | ||
``` | ||
|
||
For now, `portal` is the only project. | ||
|
||
To run headed: | ||
|
||
```bash | ||
$ npx playwright test --headed | ||
``` | ||
|
||
To run in UI mode: | ||
|
||
```bash | ||
$ npx playwright test --ui | ||
``` | ||
|
||
To show a report: | ||
|
||
```bash | ||
$ npx playwright show-report REPORT_DIR | ||
``` | ||
|
||
## Local Setup | ||
|
||
### Installation | ||
|
||
Install package: | ||
|
||
```bash | ||
$ npm i | ||
``` | ||
|
||
Install browsers: | ||
|
||
```bash | ||
$ npx playwright install | ||
``` | ||
|
||
### Configure secrets | ||
|
||
1. Copy `template.env` --> `.env` | ||
2. Fill in details |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "alcs", | ||
"version": "1.0.0", | ||
"name": "alcs-e2e-test", | ||
"version": "0.1.0", | ||
"description": "[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) ![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999) [![codecov](https://img.shields.io/codeclimate/coverage/bcgov/alcs)](https://codeclimate.com/github/bcgov/alcs)", | ||
"main": "index.js", | ||
"directories": { | ||
|
@@ -18,7 +18,9 @@ | |
"url": "https://github.com/bcgov/alcs/issues" | ||
}, | ||
"homepage": "https://github.com/bcgov/alcs#readme", | ||
"devDependencies": { | ||
"@playwright/test": "^1.32.0" | ||
"dependencies": { | ||
"@playwright/test": "^1.32.0", | ||
"@types/node": "^20.11.24", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: This doesn't matter since this won't get shipped but types should go in devDependencies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be. I considered it as a main dependency since running the E2E tests is what this package does. I think you could make the case either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The transpiled code will be JS not TS, meaning the types won't be used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Changed. |
||
"dotenv": "^16.4.5" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { defineConfig, devices } from '@playwright/test'; | ||
import 'dotenv/config'; | ||
|
||
/** | ||
* Read environment variables from file. | ||
|
@@ -35,16 +36,27 @@ export default defineConfig({ | |
{ | ||
name: 'chromium', | ||
use: { ...devices['Desktop Chrome'] }, | ||
testIgnore: '**', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this temporary? Whats the long term plan here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a base project, so is never run by itself. It just includes Chrome for use in other projects. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After re-investigating this, I don't think this works for multiple browsers. I'll come up with a better solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Project dependencies did not work how I thought. I've changed the way this works. Now, projects only select browser, and frontend is selected via directory. Each top-level directory will have its own fixtures file that sets the base URL via the environment (this will allow us to modify the URL for dev/test/local as needed). |
||
}, | ||
|
||
{ | ||
name: 'firefox', | ||
use: { ...devices['Desktop Firefox'] }, | ||
testIgnore: '**', | ||
}, | ||
|
||
{ | ||
name: 'webkit', | ||
use: { ...devices['Desktop Safari'] }, | ||
testIgnore: '**', | ||
}, | ||
{ | ||
name: 'portal', | ||
use: { | ||
baseURL: process.env.PORTAL_BASE_URL, | ||
}, | ||
dependencies: ['chromium'], | ||
testMatch: 'portal/**/*.spec.ts', | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PORTAL_BASE_URL= | ||
BCEID_BASIC_USERNAME= | ||
BCEID_BASIC_PASSWORD= |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { test as base, Page } from '@playwright/test'; | ||
export { expect } from '@playwright/test'; | ||
|
||
export enum UserPrefix { | ||
BceidBasic = 'BCEID_BASIC', | ||
} | ||
|
||
interface FixtureOptions { | ||
userPrefix: string; | ||
} | ||
|
||
interface Fixtures { | ||
inboxLoggedIn: Page; | ||
} | ||
|
||
export const test = base.extend<FixtureOptions & Fixtures>({ | ||
userPrefix: UserPrefix.BceidBasic, | ||
inboxLoggedIn: async ({ page, userPrefix }, use) => { | ||
await page.goto('/'); | ||
await page.getByRole('button', { name: 'Portal Login' }).click(); | ||
await page | ||
.locator('#user') | ||
.fill(process.env[userPrefix + '_USERNAME'] ?? ''); | ||
await page | ||
.getByLabel('Password') | ||
.fill(process.env[userPrefix + '_PASSWORD'] ?? ''); | ||
await page.getByRole('button', { name: /continue/i }).click(); | ||
await use(page); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { test, expect, UserPrefix } from '../fixtures'; | ||
|
||
test.use({ userPrefix: UserPrefix.BceidBasic }); | ||
|
||
test('test', async ({ inboxLoggedIn }) => { | ||
await expect( | ||
inboxLoggedIn.getByRole('heading', { name: 'Portal Inbox' }) | ||
).toBeVisible(); | ||
}); |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use prettier like all our other packages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied this from portal frontend, so does it need to be updated as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I have no idea what this file does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It configures the code style for editors. It's set up the same for portal and ALCS frontends, not for services. Perhaps it is part of Angular scaffolding?
For now I'll leave it, but I'll install prettier as a dev dep and include
.prettierrc
as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added prettier and eslint