Skip to content

Commit 6539a97

Browse files
- added existence waiter before value waits to avoid promise reject w… (#98)
- added existence waiter before value waits to avoid promise reject without reason error - added _restartBrowser_ config flag to restart browser between tests (default is false, considering restarting context)
1 parent 1c7fda9 commit 6539a97

File tree

9 files changed

+324
-297
lines changed

9 files changed

+324
-297
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
88
:beetle: - bugfix
99
:x: - deprecation
1010

11+
## [0.41.4]
12+
- :beetle: added existence waiter before value waits to avoid promise reject without reason error
13+
- :rocket: added _restartBrowser_ config flag to restart browser between tests (default is false, considering restarting context)
14+
1115
## [0.41.3]
1216
- :rocket: added _I type {string} chars to {string}_ step
1317

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ module.exports = {
150150
}
151151
```
152152

153+
## restartBrowser
154+
restartBrowser flag allows to restart browser between tests instead of default restarting context
155+
156+
```javascript
157+
module.exports = {
158+
default: {
159+
browser: {
160+
restartBrowser: true
161+
}
162+
}
163+
}
164+
```
165+
153166

154167
## Development and testing
155168
Install dependencies

package-lock.json

Lines changed: 278 additions & 278 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/steps-playwright",
3-
"version": "0.41.3",
3+
"version": "0.41.4",
44
"description": "steps to interact with playwright",
55
"main": "./index.js",
66
"scripts": {
@@ -35,13 +35,13 @@
3535
"@qavajs/webstorm-adapter": "^8.0.0",
3636
"@types/chai": "^4.3.11",
3737
"@types/express": "^4.17.21",
38-
"@vitest/coverage-v8": "^1.0.2",
39-
"@vitest/ui": "^1.0.2",
38+
"@vitest/coverage-v8": "^1.0.4",
39+
"@vitest/ui": "^1.0.4",
4040
"electron": "^27.1.3",
4141
"express": "^4.18.2",
42-
"ts-node": "^10.9.1",
43-
"typescript": "^5.3.2",
44-
"vitest": "^1.0.2"
42+
"ts-node": "^10.9.2",
43+
"typescript": "^5.3.3",
44+
"vitest": "^1.0.4"
4545
},
4646
"dependencies": {
4747
"@playwright/test": "^1.40.1",

src/browserManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,21 @@ export class BrowserManager {
9595
/**
9696
* return to default state (1 browser, no contexts)
9797
*/
98-
async teardown({ reuseSession } = { reuseSession: false }) {
98+
async teardown({ reuseSession, restartBrowser } = { reuseSession: false, restartBrowser: false }) {
9999
this.setDriver(this.drivers['default']);
100100
if (reuseSession) return;
101101
for (const driverKey in this.drivers) {
102102
const driverInstance = this.drivers[driverKey] as any;
103103
if (driverInstance.firstWindow) {
104104
await this.electronTeardown(driverInstance, driverKey);
105105
} else {
106-
await this.browserTeardown(driverInstance, driverKey);
106+
await this.browserTeardown(driverInstance, driverKey, restartBrowser);
107107
}
108108
}
109109
}
110110

111-
async browserTeardown(driverInstance: Browser, driverKey: string) {
112-
if (driverKey !== 'default') {
111+
async browserTeardown(driverInstance: Browser, driverKey: string, restartBrowser?: boolean) {
112+
if (driverKey !== 'default' || restartBrowser) {
113113
await driverInstance.close();
114114
delete this.drivers[driverKey];
115115
} else {

src/hooks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ AfterStep(async function (step: ITestStepHookParameter) {
7575

7676
After({name: 'Teardown'}, async function (scenario: ITestCaseHookParameter) {
7777
await tracingManager.stop(config.driverConfig, this, scenario);
78-
await browserManager.teardown({ reuseSession: config.driverConfig.reuseSession });
78+
await browserManager.teardown({
79+
reuseSession: config.driverConfig.reuseSession,
80+
restartBrowser: config.driverConfig.restartBrowser,
81+
});
7982
if (saveVideo(config.driverConfig, scenario)) {
8083
if (config.driverConfig?.video.attach) {
8184
const video = page.video();

src/validations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Then(
3030
async function (alias: string, validationType: string, value: any) {
3131
const expectedValue = await getValue(value);
3232
const element = await getElement(alias);
33+
await element.waitFor({ state: 'attached' });
3334
const validation = getPollValidation(validationType);
3435
const elementText = () => element.innerText();
3536
await validation(elementText, expectedValue, {
@@ -54,6 +55,7 @@ Then(
5455
const propertyName = await getValue(property);
5556
const expectedValue = await getValue(value);
5657
const element = await getElement(alias);
58+
await element.waitFor({ state: 'attached' });
5759
const validation = getPollValidation(validationType);
5860
const actualValue = () => element.evaluate((node: any, propertyName: string) => node[propertyName], propertyName);
5961
await validation(actualValue, expectedValue, {
@@ -77,6 +79,7 @@ Then(
7779
const attributeName = await getValue(attribute);
7880
const expectedValue = await getValue(value);
7981
const element = await getElement(alias);
82+
await element.waitFor({ state: 'attached' });
8083
const validation = getPollValidation(validationType);
8184
const actualValue = () => element.getAttribute(attributeName);
8285
await validation(actualValue, expectedValue, {
@@ -243,6 +246,7 @@ Then(
243246
const propertyName = await getValue(property);
244247
const expectedValue = await getValue(value);
245248
const element = await getElement(alias);
249+
await element.waitFor({ state: 'attached' });
246250
const validation = getPollValidation(validationType);
247251
const actualValue = () => element.evaluate(
248252
(node: Element, propertyName: string) => getComputedStyle(node).getPropertyValue(propertyName),

src/waits.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ When(
3636
async function (alias: string, waitType: string, value: string, timeout: number | null) {
3737
const wait = getPollValidation(waitType);
3838
const element = await getElement(alias);
39+
await element.waitFor({ state: 'attached' });
3940
const expectedValue = await getValue(value);
40-
const getValueFn = async () => element.innerText();
41+
const getValueFn = () => element.innerText();
4142
await wait(getValueFn, expectedValue, {
4243
timeout: timeout ?? config.browser.timeout.value,
4344
interval: config.browser.timeout.valueInterval
@@ -62,7 +63,7 @@ When(
6263
const wait = getPollValidation(waitType);
6364
const collection = await getElement(alias);
6465
const expectedValue = await getValue(value);
65-
const getValueFn = async () => collection.count();
66+
const getValueFn = () => collection.count();
6667
await wait(getValueFn, expectedValue, {
6768
timeout: timeout ?? config.browser.timeout.value,
6869
interval: config.browser.timeout.valueInterval
@@ -86,8 +87,9 @@ When(
8687
const propertyName = await getValue(property);
8788
const wait = getPollValidation(waitType);
8889
const element = await getElement(alias);
90+
await element.waitFor({ state: 'attached' });
8991
const expectedValue = await getValue(value);
90-
const getValueFn = async () => element.evaluate(
92+
const getValueFn = () => element.evaluate(
9193
(node: any, propertyName: string) => node[propertyName],
9294
propertyName
9395
);
@@ -114,8 +116,9 @@ When(
114116
const propertyName = await getValue(property);
115117
const wait = getPollValidation(waitType);
116118
const element = await getElement(alias);
119+
await element.waitFor({ state: 'attached' });
117120
const expectedValue = await getValue(value);
118-
const getValueFn = async () => element.evaluate(
121+
const getValueFn = () => element.evaluate(
119122
(node: Element, propertyName: string) => getComputedStyle(node).getPropertyValue(propertyName),
120123
propertyName
121124
);
@@ -142,8 +145,9 @@ When(
142145
const attributeName = await getValue(attribute);
143146
const wait = getPollValidation(waitType);
144147
const element = await getElement(alias);
148+
await element.waitFor({ state: 'attached' });
145149
const expectedValue = await getValue(value);
146-
const getValueFn = async () => element.getAttribute(attributeName);
150+
const getValueFn = () => element.getAttribute(attributeName);
147151
await wait(getValueFn, expectedValue, {
148152
timeout: timeout ?? config.browser.timeout.value,
149153
interval: config.browser.timeout.valueInterval
@@ -176,7 +180,7 @@ When(
176180
async function (waitType: string, value: string, timeout: number | null) {
177181
const wait = getPollValidation(waitType);
178182
const expectedValue = await getValue(value);
179-
const getValueFn = async () => page.url();
183+
const getValueFn = () => page.url();
180184
await wait(getValueFn, expectedValue, {
181185
timeout: timeout ?? config.browser.timeout.value,
182186
interval: config.browser.timeout.valueInterval
@@ -198,7 +202,7 @@ When(
198202
async function (waitType: string, value: string, timeout: number | null) {
199203
const wait = getPollValidation(waitType);
200204
const expectedValue = await getValue(value);
201-
const getValueFn = async () => page.title();
205+
const getValueFn = () => page.title();
202206
await wait(getValueFn, expectedValue, {
203207
timeout: timeout ?? config.browser.timeout.value,
204208
interval: config.browser.timeout.valueInterval

test-e2e/webui.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const common = {
2525
attach: true
2626
},
2727
screenshot: ['onFail'],
28-
2928
},
3029
format: [
3130
'@qavajs/console-formatter',

0 commit comments

Comments
 (0)