Skip to content

Commit 6fc77eb

Browse files
author
Oleksandr_Halichenko
committed
implemented context reload instead browser
1 parent ec7cf6f commit 6fc77eb

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
66

77
## [0.0.20]
88
- :rocket: enabled all options in new context
9+
- :rocket: implemented context reload instead browser
910

1011
## [0.0.19]
1112
- :rocket: added to match value wait

src/hooks.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { After, AfterStep, Before, BeforeStep } from '@cucumber/cucumber';
1+
import {
2+
After,
3+
AfterAll,
4+
AfterStep,
5+
Before,
6+
BeforeStep,
7+
ITestCaseHookParameter,
8+
ITestStepHookParameter
9+
} from '@cucumber/cucumber';
210
import defaultTimeouts from './defaultTimeouts';
311
import { Browser, BrowserContext, Page } from 'playwright';
412
import { po } from '@qavajs/po-playwright';
@@ -21,7 +29,8 @@ Before(async function () {
2129
...driverConfig.timeout
2230
}
2331
config.driverConfig = driverConfig;
24-
global.browser = await driverProvider(config.driverConfig);
32+
33+
global.browser = global.browser ? global.browser : await driverProvider(config.driverConfig);
2534
global.context = await browser.newContext(config?.driverConfig?.capabilities);
2635
if (config.driverConfig.trace) {
2736
await context.tracing.start({
@@ -46,7 +55,7 @@ BeforeStep(async function () {
4655
}
4756
});
4857

49-
AfterStep(async function (step) {
58+
AfterStep(async function (step: ITestStepHookParameter) {
5059
try {
5160
if (saveScreenshotAfterStep(config, step)) {
5261
this.attach(await page.screenshot(), 'image/png');
@@ -56,7 +65,7 @@ AfterStep(async function (step) {
5665
}
5766
});
5867

59-
After(async function (scenario) {
68+
After(async function (scenario: ITestCaseHookParameter) {
6069
if (saveTrace(config.driverConfig, scenario)) {
6170
const path = traceArchive(config.driverConfig, scenario);
6271
await context.tracing.stop({ path });
@@ -65,8 +74,14 @@ After(async function (scenario) {
6574
this.attach(zipBuffer.toString('base64'), 'base64:application/zip');
6675
}
6776
}
77+
if (global.browser) {
78+
await context.close();
79+
this.log('browser context closed');
80+
}
81+
});
82+
83+
AfterAll(async function () {
6884
if (global.browser) {
6985
await browser.close();
70-
this.log('browser instance closed');
7186
}
7287
});

0 commit comments

Comments
 (0)