Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
:beetle: - bugfix
:x: - deprecation

## [0.41.4]
- :beetle: added existence waiter before value waits to avoid promise reject without reason error
- :rocket: added _restartBrowser_ config flag to restart browser between tests (default is false, considering restarting context)

## [0.41.3]
- :rocket: added _I type {string} chars to {string}_ step

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ module.exports = {
}
```

## restartBrowser
restartBrowser flag allows to restart browser between tests instead of default restarting context

```javascript
module.exports = {
default: {
browser: {
restartBrowser: true
}
}
}
```


## Development and testing
Install dependencies
Expand Down
556 changes: 278 additions & 278 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qavajs/steps-playwright",
"version": "0.41.3",
"version": "0.41.4",
"description": "steps to interact with playwright",
"main": "./index.js",
"scripts": {
Expand Down Expand Up @@ -35,13 +35,13 @@
"@qavajs/webstorm-adapter": "^8.0.0",
"@types/chai": "^4.3.11",
"@types/express": "^4.17.21",
"@vitest/coverage-v8": "^1.0.2",
"@vitest/ui": "^1.0.2",
"@vitest/coverage-v8": "^1.0.4",
"@vitest/ui": "^1.0.4",
"electron": "^27.1.3",
"express": "^4.18.2",
"ts-node": "^10.9.1",
"typescript": "^5.3.2",
"vitest": "^1.0.2"
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vitest": "^1.0.4"
},
"dependencies": {
"@playwright/test": "^1.40.1",
Expand Down
8 changes: 4 additions & 4 deletions src/browserManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ export class BrowserManager {
/**
* return to default state (1 browser, no contexts)
*/
async teardown({ reuseSession } = { reuseSession: false }) {
async teardown({ reuseSession, restartBrowser } = { reuseSession: false, restartBrowser: false }) {
this.setDriver(this.drivers['default']);
if (reuseSession) return;
for (const driverKey in this.drivers) {
const driverInstance = this.drivers[driverKey] as any;
if (driverInstance.firstWindow) {
await this.electronTeardown(driverInstance, driverKey);
} else {
await this.browserTeardown(driverInstance, driverKey);
await this.browserTeardown(driverInstance, driverKey, restartBrowser);
}
}
}

async browserTeardown(driverInstance: Browser, driverKey: string) {
if (driverKey !== 'default') {
async browserTeardown(driverInstance: Browser, driverKey: string, restartBrowser?: boolean) {
if (driverKey !== 'default' || restartBrowser) {
await driverInstance.close();
delete this.drivers[driverKey];
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ AfterStep(async function (step: ITestStepHookParameter) {

After({name: 'Teardown'}, async function (scenario: ITestCaseHookParameter) {
await tracingManager.stop(config.driverConfig, this, scenario);
await browserManager.teardown({ reuseSession: config.driverConfig.reuseSession });
await browserManager.teardown({
reuseSession: config.driverConfig.reuseSession,
restartBrowser: config.driverConfig.restartBrowser,
});
if (saveVideo(config.driverConfig, scenario)) {
if (config.driverConfig?.video.attach) {
const video = page.video();
Expand Down
4 changes: 4 additions & 0 deletions src/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Then(
async function (alias: string, validationType: string, value: any) {
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const validation = getPollValidation(validationType);
const elementText = () => element.innerText();
await validation(elementText, expectedValue, {
Expand All @@ -54,6 +55,7 @@ Then(
const propertyName = await getValue(property);
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const validation = getPollValidation(validationType);
const actualValue = () => element.evaluate((node: any, propertyName: string) => node[propertyName], propertyName);
await validation(actualValue, expectedValue, {
Expand All @@ -77,6 +79,7 @@ Then(
const attributeName = await getValue(attribute);
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const validation = getPollValidation(validationType);
const actualValue = () => element.getAttribute(attributeName);
await validation(actualValue, expectedValue, {
Expand Down Expand Up @@ -243,6 +246,7 @@ Then(
const propertyName = await getValue(property);
const expectedValue = await getValue(value);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const validation = getPollValidation(validationType);
const actualValue = () => element.evaluate(
(node: Element, propertyName: string) => getComputedStyle(node).getPropertyValue(propertyName),
Expand Down
18 changes: 11 additions & 7 deletions src/waits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ When(
async function (alias: string, waitType: string, value: string, timeout: number | null) {
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const expectedValue = await getValue(value);
const getValueFn = async () => element.innerText();
const getValueFn = () => element.innerText();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
Expand All @@ -62,7 +63,7 @@ When(
const wait = getPollValidation(waitType);
const collection = await getElement(alias);
const expectedValue = await getValue(value);
const getValueFn = async () => collection.count();
const getValueFn = () => collection.count();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
Expand All @@ -86,8 +87,9 @@ When(
const propertyName = await getValue(property);
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const expectedValue = await getValue(value);
const getValueFn = async () => element.evaluate(
const getValueFn = () => element.evaluate(
(node: any, propertyName: string) => node[propertyName],
propertyName
);
Expand All @@ -114,8 +116,9 @@ When(
const propertyName = await getValue(property);
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const expectedValue = await getValue(value);
const getValueFn = async () => element.evaluate(
const getValueFn = () => element.evaluate(
(node: Element, propertyName: string) => getComputedStyle(node).getPropertyValue(propertyName),
propertyName
);
Expand All @@ -142,8 +145,9 @@ When(
const attributeName = await getValue(attribute);
const wait = getPollValidation(waitType);
const element = await getElement(alias);
await element.waitFor({ state: 'attached' });
const expectedValue = await getValue(value);
const getValueFn = async () => element.getAttribute(attributeName);
const getValueFn = () => element.getAttribute(attributeName);
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
Expand Down Expand Up @@ -176,7 +180,7 @@ When(
async function (waitType: string, value: string, timeout: number | null) {
const wait = getPollValidation(waitType);
const expectedValue = await getValue(value);
const getValueFn = async () => page.url();
const getValueFn = () => page.url();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
Expand All @@ -198,7 +202,7 @@ When(
async function (waitType: string, value: string, timeout: number | null) {
const wait = getPollValidation(waitType);
const expectedValue = await getValue(value);
const getValueFn = async () => page.title();
const getValueFn = () => page.title();
await wait(getValueFn, expectedValue, {
timeout: timeout ?? config.browser.timeout.value,
interval: config.browser.timeout.valueInterval
Expand Down
1 change: 0 additions & 1 deletion test-e2e/webui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const common = {
attach: true
},
screenshot: ['onFail'],

},
format: [
'@qavajs/console-formatter',
Expand Down