@spscommerce/e2e-core 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +4 -3
- package/README.md +14 -12
- package/package.json +1 -1
- package/playwright.config.js +19 -15
package/Dockerfile
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
FROM mcr.microsoft.com/playwright:v1.
|
|
1
|
+
FROM mcr.microsoft.com/playwright:v1.22.0-alpha-1652194905000-focal
|
|
2
2
|
|
|
3
3
|
ARG BROWSER
|
|
4
4
|
|
|
5
5
|
RUN mkdir e2e
|
|
6
6
|
WORKDIR /e2e
|
|
7
7
|
COPY . .
|
|
8
|
-
RUN
|
|
9
|
-
RUN if [ "$BROWSER" = "
|
|
8
|
+
RUN yarn
|
|
9
|
+
RUN if [ "$BROWSER" = "edge" ]; then npx playwright install msedge; fi
|
|
10
|
+
RUN if [ "$BROWSER" = "chrome" ]; then npx playwright install chrome; fi
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ VIEWPORT={"width": 1920, "height": 1080}
|
|
|
32
32
|
| ENV | auth state is invoked for the defined env | test | test, prod |
|
|
33
33
|
| TEST_TIMEOUT | global timeout for each test | 30000 | [number_in_ms] |
|
|
34
34
|
| ACTION_TIMEOUT | global timeout for each PW action, like click() | 30000 | [number_in_ms] |
|
|
35
|
+
| SLOWMO | slows down the actions by the specified ms | 0 | [number_in_ms] |
|
|
35
36
|
| WORKERS | number of workers (test threads) | 1 | [number] |
|
|
36
37
|
| TRACER | create PW actions trace file per each failed test | false | true, false |
|
|
37
38
|
| VIEWPORT | emulates consistent viewport for each page | {"width": 1536, "height": 960} | [string] |
|
|
@@ -44,15 +45,15 @@ VIEWPORT={"width": 1920, "height": 1080}
|
|
|
44
45
|
|
|
45
46
|
6. Setup the following "scripts" commands in the `package.json` according to your paths:
|
|
46
47
|
```
|
|
47
|
-
"test": ". .credentials.sh && CONFIG_PATH=$(pwd)/.env SETUP_PATH=$(pwd)/src/
|
|
48
|
+
"test": ". .credentials.sh && CONFIG_PATH=$(pwd)/.env SETUP_PATH=$(pwd)/src/helpers/urlSetup.js TEST_DIR=$(pwd) HEADLESS=false playwright test --config=node_modules/@spscommerce/e2e-core/playwright.config.js",
|
|
48
49
|
"test:ci": "CONFIG_PATH=$(pwd)/.env SETUP_PATH=$(pwd)/src/helpers/urlSetup.js TEST_DIR=$(pwd) CI=true playwright test --config=node_modules/@spscommerce/e2e-core/playwright.config.js"
|
|
49
50
|
```
|
|
50
51
|
7. Add your first test file:
|
|
51
52
|
```
|
|
52
|
-
import {
|
|
53
|
+
import { test } from '@playwright/test';
|
|
53
54
|
import { enableLogger, disableLogger, expect } from '@spscommerce/e2e-core';
|
|
54
55
|
|
|
55
|
-
test.describe('
|
|
56
|
+
test.describe('SPS_MyFirstTestSuite', () => {
|
|
56
57
|
|
|
57
58
|
test.beforeEach(async ({}, testInfo) => {
|
|
58
59
|
await enableLogger(testInfo.titlePath, page);
|
|
@@ -62,7 +63,7 @@ test.describe('SPS_MyFirstTest', () => {
|
|
|
62
63
|
await disableLogger();
|
|
63
64
|
});
|
|
64
65
|
|
|
65
|
-
test('Transactions_is_opened_with_content', async () => {
|
|
66
|
+
test('Transactions_is_opened_with_content', async ({ page }) => {
|
|
66
67
|
await page.goto(https://test.commerce.spscommerce.com/);
|
|
67
68
|
await page.waitForTimeout(10000);
|
|
68
69
|
});
|
|
@@ -74,10 +75,10 @@ test.describe('SPS_MyFirstTest', () => {
|
|
|
74
75
|
### Additional options
|
|
75
76
|
If CI is set to true, the forbidOnly and maxFailures options are applied.
|
|
76
77
|
- forbidOnly: Fail the build on CI if you accidentally left test.only in the source code
|
|
77
|
-
- maxFailures: Stop test suite execution after reaching
|
|
78
|
+
- maxFailures: Stop test suite execution after reaching 8 failed tests and skip any tests that were not executed yet.
|
|
78
79
|
|
|
79
80
|
### Authentication
|
|
80
|
-
Authentication flow was implemented in the e2e-core library. When tests are launnhed for the first time, it takes some time for the authentication state to be invoked. If ENV variable is not set, the storageState is created for the test environment, otherwise set
|
|
81
|
+
Authentication flow was implemented in the e2e-core library. When tests are launnhed for the first time, it takes some time for the authentication state to be invoked. If ENV variable is not set, the storageState is created for the test environment, otherwise set ENV to 'prod'. After auth state is invoked, it appears in the results-e2e/auth folder. All the next test runs will use an already created storageState.json file till its TTL. After TTL is reached, the auth state is invoked again.
|
|
81
82
|
|
|
82
83
|
### Global setup
|
|
83
84
|
To set something up once before running all tests, create a JS file and link it via SETUP_PATH variable in the `package.json`. Global setup file must export a single function that runs once before all the tests.
|
|
@@ -87,7 +88,7 @@ After tests finishes, you can observe test results in the results-e2e/ folder:
|
|
|
87
88
|
- screenshot folder with screen and trace file (if TRACER=true) for each failed test
|
|
88
89
|
- log folder with log file for each test regardless its status
|
|
89
90
|
- reports folder with compatible junit xml files (Azure test results friendly format)
|
|
90
|
-
- auth folder with an invoked auth state
|
|
91
|
+
- auth folder with an invoked auth state per ENV
|
|
91
92
|
|
|
92
93
|
### Tracer
|
|
93
94
|
You can observe the PW trace file in 3 ways:
|
|
@@ -98,22 +99,23 @@ You can observe the PW trace file in 3 ways:
|
|
|
98
99
|
## Dockerfile
|
|
99
100
|
PW provides an official Docker image. These image includes all the dependencies needed to run browsers in a Docker container, and also include the browsers themselves. Here is an example of the Dockerfile:
|
|
100
101
|
```
|
|
101
|
-
FROM mcr.microsoft.com/playwright:v1.22.0-focal
|
|
102
|
+
FROM mcr.microsoft.com/playwright:v1.22.0-alpha-1652194905000-focal
|
|
102
103
|
|
|
103
104
|
ARG BROWSER
|
|
104
105
|
|
|
105
106
|
RUN mkdir e2e
|
|
106
107
|
WORKDIR /e2e
|
|
107
108
|
COPY . .
|
|
108
|
-
RUN
|
|
109
|
-
RUN if [ "$BROWSER" = "
|
|
109
|
+
RUN yarn
|
|
110
|
+
RUN if [ "$BROWSER" = "edge" ]; then npx playwright install msedge; fi
|
|
111
|
+
RUN if [ "$BROWSER" = "chrome" ]; then npx playwright install chrome; fi
|
|
110
112
|
```
|
|
111
113
|
> Attention:
|
|
112
114
|
> Installed Playwright package version must match the Docker image version.
|
|
113
115
|
|
|
114
116
|
## Run tests in CI (Azure Pipelines)
|
|
115
117
|
In order to add an Azure Pipeline for your framework, head over to https://dev.azure.com/spscommerce/ and find your team. You can create a new pipeline by selecting your Git repository. For more information on getting started with Azure, visit https://github.com/SPSCommerce/azure-pipelines-config.
|
|
116
|
-
> Attention: Do not forget to set up USER_EMAIL and USER_PASSWORD variables in Azure UI.
|
|
118
|
+
> Attention: Do not forget to set up USER_EMAIL and USER_PASSWORD private variables in Azure UI.
|
|
117
119
|
Here is an example of a job in the yaml file:
|
|
118
120
|
```
|
|
119
121
|
jobs:
|
|
@@ -135,7 +137,7 @@ jobs:
|
|
|
135
137
|
USER_PASSWORD=$(USER_PASSWORD)
|
|
136
138
|
USER_EMAIL=$(USER_EMAIL)
|
|
137
139
|
BROWSER=${{parameters.browser}}
|
|
138
|
-
|
|
140
|
+
ENV=${{parameters.url}}
|
|
139
141
|
SUITE=$(suite)
|
|
140
142
|
CI=true
|
|
141
143
|
dockerCmd: |
|
package/package.json
CHANGED
package/playwright.config.js
CHANGED
|
@@ -62,7 +62,7 @@ switch (process.env.BROWSER) {
|
|
|
62
62
|
}];
|
|
63
63
|
break;
|
|
64
64
|
}
|
|
65
|
-
// Added a specific no-retry suite workaround till the following request is done
|
|
65
|
+
// Added a specific no-retry suite workaround till the following request is done
|
|
66
66
|
// https://github.com/microsoft/playwright/issues/10825
|
|
67
67
|
browserProject.push(
|
|
68
68
|
{
|
|
@@ -81,51 +81,55 @@ const storageStatePath = process.env.ENV && process.env.ENV.includes('prod')
|
|
|
81
81
|
: path.join(process.cwd(), 'results-e2e/auth/storageStateTest.json');
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
* See https://playwright.dev/docs/test-configuration
|
|
84
|
+
* See https://playwright.dev/docs/test-configuration
|
|
85
85
|
*/
|
|
86
86
|
|
|
87
87
|
// @ts-check
|
|
88
88
|
/** @type {import('@playwright/test').PlaywrightTestConfig} */
|
|
89
89
|
const config = {
|
|
90
|
-
/* Directory that will be recursively scanned for test files
|
|
90
|
+
/* Directory that will be recursively scanned for test files */
|
|
91
91
|
testDir: process.env.TEST_DIR,
|
|
92
92
|
/* Maximum time one test can run for. */
|
|
93
93
|
timeout: +process.env.TEST_TIMEOUT || 30000,
|
|
94
|
-
/* Maximum time expect() should wait for the condition to be met
|
|
94
|
+
/* Maximum time expect() should wait for the condition to be met */
|
|
95
95
|
expect: {
|
|
96
96
|
timeout: 5000
|
|
97
97
|
},
|
|
98
|
-
/* Fail the build on CI if you accidentally left test.only in the source code
|
|
98
|
+
/* Fail the build on CI if you accidentally left test.only in the source code */
|
|
99
99
|
forbidOnly: !!process.env.CI,
|
|
100
100
|
/* Retry on CI only */
|
|
101
|
-
retries:
|
|
102
|
-
/* Opt out of parallel tests on CI
|
|
101
|
+
retries: +process.env.RETRIES || 0,
|
|
102
|
+
/* Opt out of parallel tests on CI */
|
|
103
103
|
workers: +process.env.WORKERS || 1,
|
|
104
|
-
/* Stop test suite execution after reaching this number of failed tests and skip any tests that were not executed yet
|
|
105
|
-
maxFailures: process.env.CI ?
|
|
104
|
+
/* Stop test suite execution after reaching this number of failed tests and skip any tests that were not executed yet */
|
|
105
|
+
maxFailures: process.env.CI ? 8 : 0,
|
|
106
106
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
107
107
|
reporter: [
|
|
108
108
|
['junit', { outputFile: path.join(process.cwd(), `results-e2e/reports/${reportName}`) }],
|
|
109
109
|
['list']
|
|
110
110
|
],
|
|
111
|
-
/* Global setup file must export a single function. This function will be run once before all the tests
|
|
111
|
+
/* Global setup file must export a single function. This function will be run once before all the tests */
|
|
112
112
|
globalSetup: require.resolve('./lib/globalSetup'),
|
|
113
113
|
/* Similarly, run something once after all the tests. */
|
|
114
114
|
globalTeardown: require.resolve('./lib/globalTeardown'),
|
|
115
|
-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions
|
|
115
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions */
|
|
116
116
|
use: {
|
|
117
117
|
storageState: storageStatePath,//path.join(process.cwd(), 'results-e2e/auth/storageState.json'),
|
|
118
|
-
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit)
|
|
118
|
+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit) */
|
|
119
119
|
actionTimeout: +process.env.ACTION_TIMEOUT || 30000,
|
|
120
120
|
/* Collect screenshot after each test failure. See https://playwright.dev/docs/test-configuration#automatic-screenshots */
|
|
121
121
|
screenshot: 'only-on-failure',
|
|
122
122
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
123
123
|
trace: process.env.TRACER && (process.env.TRACER.toString().toLowerCase() === 'true') ? 'retain-on-failure' : 'off',
|
|
124
|
-
/* Run in headless mode by default (if process.env.HEADLESS is not specified)
|
|
124
|
+
/* Run in headless mode by default (if process.env.HEADLESS is not specified) */
|
|
125
125
|
headless: !process.env.HEADLESS || process.env.HEADLESS === 'true' ? true : false,
|
|
126
|
-
/* Whether to ignore HTTPS errors when sending network requests
|
|
126
|
+
/* Whether to ignore HTTPS errors when sending network requests */
|
|
127
127
|
ignoreHTTPSErrors: true,
|
|
128
|
-
/*
|
|
128
|
+
/* Slow down Playwright operations by the specified amount of milliseconds */
|
|
129
|
+
launchOptions: {
|
|
130
|
+
slowMo: +process.env.SLOWMO || 0,
|
|
131
|
+
}
|
|
132
|
+
/* Base URL to use in actions like `await page.goto('/')` */
|
|
129
133
|
// baseURL: 'http://localhost:3000',
|
|
130
134
|
},
|
|
131
135
|
/* Configure projects for major browsers */
|