-
Notifications
You must be signed in to change notification settings - Fork 57
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
Playwright e2e reconfiguration #871
Changes from 23 commits
d85490a
afcafcc
5641052
afdd8a5
54b8f25
0782a63
c0e2b4f
c45e491
5091475
465aac2
6a60e5a
843c7b9
18640cf
bc05caa
a0436db
6bb6084
4222b1c
4df1766
5625680
12e0848
0641730
5a7dacb
6957862
c73625d
a1777a6
afe2841
cebb28f
bb40245
9e30243
34b48ee
be49509
fcb7a26
26b66b1
20895a1
2d4cc3b
b207020
b4abc81
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ api/ | |
build/ | ||
config/ | ||
node_modules/ | ||
script/ | ||
script/ | ||
coverage/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
playwright/.auth/ | ||
playwright/.auth/ | ||
test-results/ |
prasadtalasila marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
# End-to-End (E2E) Tests | ||
|
||
The E2E tests require a functional gitlab oauth setup, traefik gateway and a | ||
live react client website. The E2E tests do not launch the react client website. | ||
So it is important to launch the website using `yarn start`. Keep this server | ||
running while performing the E2E tests with `yarn test:e2e` command. | ||
The E2E tests require playwright test runner, an on-premise GitLab OAuth setup and | ||
configured `config/test.js` and `test/.env` files. When everything is set up, you | ||
can run the tests by running `yarn test:e2e`. | ||
|
||
By default, Playwright launches the react client website as specified in `config/test.js` | ||
and terminates it afterwards. Running `yarn test:e2e:int` allows you to skip this so | ||
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. Line length |
||
you can host the website yourself. | ||
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. Does this mean that we can host the client at a doman address (say sandbox.cps.digit.au.dk) and perform E2E tests? |
||
|
||
## Playwright | ||
|
||
The E2E tests use playwright test runner. You also need to have the software | ||
installed. If it is not installed, you can install with the following command. | ||
installed. If it is not installed, you can install it with the following command. | ||
|
||
```bash | ||
sudo npx playwright install-deps | ||
yarn playwright install --with-deps | ||
``` | ||
|
||
## OAuth Setup | ||
|
||
You can follow the instructions in | ||
[authorization page](../../docs/admin/client/auth.md) to setup oauth for the | ||
You can follow the instructions in [authorization page](../../docs/admin/client/auth.md) to setup OAuth for the | ||
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. Line length |
||
react client website. Remember to add the `http://localhost:4000` as callback URL | ||
in the oauth application. The gitlab will still be running on a remote machine. | ||
It is not possible to run both the gitlab and react client website on localhost. | ||
in the OAuth application. The GitLab will still be running on a remote machine. | ||
It is not possible to run both the GitLab and react client website on localhost. | ||
|
||
## config/test.js file | ||
|
||
|
@@ -35,8 +39,7 @@ the details of your testing environment. For instance, you need to adjust: | |
* `REACT_APP_LOGOUT_REDIRECT_URI` | ||
|
||
to reflect your test setup. More information on about the environment settings is | ||
available in [authorization](../../docs/admin/client/auth.md) and | ||
[client deployment](../../docs/admin/client/CLIENT.md) pages. | ||
available in [authorization](../../docs/admin/client/auth.md) and [client deployment](../../docs/admin/client/CLIENT.md) pages. | ||
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. Line length |
||
|
||
Here's an example of relevant values for variables. This example is suitable for | ||
testing on developer computer. | ||
|
@@ -48,6 +51,8 @@ REACT_APP_REDIRECT_URI="http://localhost:4000/Library" | |
REACT_APP_LOGOUT_REDIRECT_URI="http://localhost:4000" | ||
``` | ||
|
||
Finally, run `yarn config:test` to copy the config file into the `build` and `public` folders. | ||
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. Line length |
||
|
||
## env file | ||
|
||
You need to create a `test/.env` file where you will store the GitLab user | ||
|
@@ -77,7 +82,8 @@ REACT_APP_URL='http://localhost:4000' | |
|
||
## Testing on localhost | ||
|
||
There are two possible testing setups you can create. | ||
If you want to handle starting the react client server yourself, there are two | ||
possible testing setups you can create. | ||
|
||
1. Host website on the developer computer and test from developer computer | ||
1. Host website on the integration server and test from the integration server | ||
|
@@ -127,7 +133,7 @@ credentials on `gitlab.foo.com`. | |
## Testing on the integration server | ||
|
||
In this test setup, the DTaaS application is running at `https://foo.com` and | ||
the gitlab instance is running at `https://gitlab.foo.com`. The E2E test shall | ||
the GitLab instance is running at `https://gitlab.foo.com`. The E2E test shall | ||
be run from the developer computer. The codebase commit should be the same on | ||
both the developer computer and integration server. | ||
|
||
|
@@ -150,7 +156,7 @@ window.env = { | |
REACT_APP_AUTH_AUTHORITY: 'https://gitlab.foo.com/', | ||
REACT_APP_REDIRECT_URI: 'https://foo.com/Library', | ||
REACT_APP_LOGOUT_REDIRECT_UR: 'https://foo.com/', | ||
REACT_APP_GITLAB_SCOPES: 'openid profile read_user read_repository api', | ||
REACT_APP_GitLab_SCOPES: 'openid profile read_user read_repository api', | ||
}; | ||
``` | ||
|
||
|
@@ -171,12 +177,19 @@ gateway and the client website hosted behind traefik. | |
|
||
## Running the Tests | ||
|
||
Once you've properly set up your .env file, you can now run the end-to-end tests. | ||
Once you've properly set up your .env file, you can run the end-to-end tests as follows: | ||
|
||
```bash | ||
yarn test:e2e | ||
``` | ||
Or with manual website launch: | ||
```bash | ||
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. Fenced code blocks should be surrounded by blank lines |
||
yarn test:e2e:int | ||
``` | ||
|
||
These commands launch the test runner and execute all end-to-end tests. The first | ||
command also runs the `yarn start` command to start the client website | ||
and terminates it after testing. | ||
|
||
This command launches the test runner and executes all end-to-end tests. | ||
Make sure you have an active internet connection while running these tests, | ||
as they simulate real user interactions with your GitLab account. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { test as testBase } from '@playwright/test'; | ||
import MCR from 'monocart-coverage-reports'; | ||
import coverageOptions from './mcr.config'; | ||
|
||
// fixtures | ||
const test = testBase.extend<{ | ||
autoTestFixture: string; | ||
}>({ | ||
autoTestFixture: [ | ||
async ({ page }, use) => { | ||
const isChromium = test.info().project.name === 'chromium'; | ||
|
||
// console.log('autoTestFixture setup...'); | ||
// coverage API is chromium only | ||
if (isChromium) { | ||
await Promise.all([ | ||
page.coverage.startJSCoverage({ | ||
resetOnNavigation: false, | ||
}), | ||
page.coverage.startCSSCoverage({ | ||
resetOnNavigation: false, | ||
}), | ||
]); | ||
} | ||
|
||
await use('autoTestFixture'); | ||
|
||
// console.log('autoTestFixture teardown...'); | ||
if (isChromium) { | ||
const [jsCoverage, cssCoverage] = await Promise.all([ | ||
page.coverage.stopJSCoverage(), | ||
page.coverage.stopCSSCoverage(), | ||
]); | ||
const coverageList = [...jsCoverage, ...cssCoverage]; | ||
// console.log(coverageList.map((item) => item.url)); | ||
const mcr = MCR(coverageOptions); | ||
await mcr.add(coverageList); | ||
} | ||
}, | ||
{ | ||
scope: 'test', | ||
auto: true, | ||
}, | ||
], | ||
}); | ||
|
||
export default test; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import MCR from 'monocart-coverage-reports'; | ||
import coverageOptions from './mcr.config'; | ||
|
||
async function globalTeardown() { | ||
const mcr = MCR(coverageOptions); | ||
await mcr.generate(); | ||
} | ||
|
||
export default globalTeardown; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import MCR from 'monocart-coverage-reports'; | ||
import coverageOptions from './mcr.config'; | ||
|
||
async function globalSetup() { | ||
const mcr = MCR(coverageOptions); | ||
await mcr.cleanCache(); | ||
} | ||
|
||
export default globalSetup; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CoverageReportOptions } from 'monocart-coverage-reports'; | ||
|
||
// https://github.com/cenfun/monocart-coverage-reports | ||
const coverageOptions: CoverageReportOptions = { | ||
name: 'Playwright Monocart Coverage Reports', | ||
|
||
reports: ['codecov', 'v8', 'console-summary'], | ||
|
||
outputDir: './coverage/e2e', | ||
}; | ||
|
||
export default coverageOptions; |
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.
Please keep this. Otherwise, this workflow runs too many times.