-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
202 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Feature: hooks | ||
Feature: sample | ||
|
||
Background: bg | ||
Given Step bg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
import timers from 'node:timers/promises'; | ||
import { test as base, createBdd } from 'playwright-bdd'; | ||
|
||
const logger = console; | ||
|
||
export const test = base.extend<{ fixtureForFoo: void; fixtureForBar: void }>({ | ||
fixtureForFoo: async ({}, use) => { | ||
logger.log(`setup fixture for foo`); | ||
export const test = base.extend< | ||
{ fixtureForFoo: void; fixtureForBar: void }, | ||
{ track: (s: string) => unknown } | ||
>({ | ||
fixtureForFoo: async ({ track }, use) => { | ||
// tiny delay to have always foo after bar | ||
await timers.setTimeout(50); | ||
track(`setup fixture for foo`); | ||
await use(); | ||
}, | ||
|
||
fixtureForBar: async ({}, use) => { | ||
logger.log(`setup fixture for bar`); | ||
fixtureForBar: async ({ track }, use) => { | ||
track(`setup fixture for bar`); | ||
await use(); | ||
}, | ||
|
||
track: [ | ||
async ({}, use, workerInfo) => { | ||
const fn = (hookTitle: string) => { | ||
logger.log(`worker ${workerInfo.workerIndex}: ${hookTitle}`); | ||
}; | ||
await use(fn); | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
}); | ||
|
||
export const { Given, Before, After, AfterAll } = createBdd(test); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Feature: sample | ||
Feature: sample 2 | ||
|
||
Scenario: scenario 3 | ||
Given step in sample2 | ||
Given Step 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import { Given } from './fixtures'; | ||
import { track } from './track'; | ||
import { expect } from '@playwright/test'; | ||
import { Given, Before, After } from './fixtures'; | ||
|
||
const logger = console; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
Before('@bar', async function ({ $testInfo, $tags, track, fixtureForBar }) { | ||
track(`Before @bar ${$testInfo.title}`); | ||
expect($tags).toEqual(['@foo', '@bar']); | ||
}); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
Before({ tags: '@foo and not @bar' }, async ({ $testInfo, track, fixtureForFoo }) => { | ||
track(`Before @foo and not @bar ${$testInfo.title}`); | ||
}); | ||
|
||
After('@bar', async function ({ $testInfo, $tags, track }) { | ||
track(`After @bar ${$testInfo.title}`); | ||
expect($tags).toEqual(['@foo', '@bar']); | ||
}); | ||
|
||
Given('State {int}', async ({ $testInfo }) => { | ||
track(`Step ${$testInfo.title}`); | ||
After({ tags: '@foo and not @bar' }, async ({ $testInfo, track }) => { | ||
track(`After @foo and not @bar ${$testInfo.title}`); | ||
}); | ||
|
||
Given('step in sample2', async () => { | ||
logger.log(`step in sample2`); | ||
Given('Step {int}', async ({ $step, track }) => { | ||
track($step.title); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import timers from 'node:timers/promises'; | ||
import { test as base, createBdd } from 'playwright-bdd'; | ||
|
||
const logger = console; | ||
|
||
export const test = base.extend<object, { track: (s: string) => unknown }>({ | ||
track: [ | ||
async ({}, use, workerInfo) => { | ||
const fn = async (hookTitle: string) => { | ||
logger.log(`worker ${workerInfo.workerIndex}: ${hookTitle}`); | ||
const shouldTimeout = process.env.TIMEOUT && hookTitle.startsWith(process.env.TIMEOUT); | ||
if (shouldTimeout) { | ||
await timers.setTimeout(100); | ||
} | ||
}; | ||
await use(fn); | ||
}, | ||
{ scope: 'worker' }, | ||
], | ||
}); | ||
|
||
export const { Given, Before, BeforeAll, After, AfterAll } = createBdd(test); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Given, Before, BeforeAll, After, AfterAll } from './fixtures'; | ||
|
||
// scenario hooks | ||
|
||
Before({ timeout: 5 }, async function ({ $testInfo, track }) { | ||
await track(`Before 1 ${$testInfo.title}`); | ||
}); | ||
|
||
Before(async ({ $testInfo, track }) => { | ||
await track(`Before 2 ${$testInfo.title}`); | ||
}); | ||
|
||
After(async function ({ $testInfo, track }) { | ||
await track(`After 1 ${$testInfo.title}`); | ||
}); | ||
|
||
After({ timeout: 5 }, async ({ $testInfo, track }) => { | ||
await track(`After 2 ${$testInfo.title}`); | ||
}); | ||
|
||
// worker hooks | ||
|
||
BeforeAll({ timeout: 5 }, async function ({ track }) { | ||
await track(`BeforeAll 1`); | ||
}); | ||
|
||
BeforeAll(async ({ track }) => { | ||
await track(`BeforeAll 2`); | ||
}); | ||
|
||
AfterAll(async function ({ track }) { | ||
await track(`AfterAll 1`); | ||
}); | ||
|
||
AfterAll({ timeout: 5 }, async ({ track }) => { | ||
await track(`AfterAll 2`); | ||
}); | ||
|
||
// step | ||
|
||
Given('State {int}', async ({ $testInfo, track }) => { | ||
await track(`Step ${$testInfo.title}`); | ||
}); |
Oops, something went wrong.