-
-
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.
support scoped step definitions (#205)
- Loading branch information
Showing
15 changed files
with
154 additions
and
17 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
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ProvidedStepOptions, StepDefinitionOptions, StepPattern } from '../stepDefinition'; | ||
|
||
export type StepDefinitionArgs<StepFn extends StepDefinitionOptions['fn']> = | ||
| [pattern: StepPattern, fn: StepFn] | ||
| [pattern: StepPattern, providedOptions: ProvidedStepOptions, fn: StepFn]; | ||
|
||
export function parseStepDefinitionArgs<StepFn extends StepDefinitionOptions['fn']>( | ||
args: StepDefinitionArgs<StepFn>, | ||
) { | ||
const [pattern, providedOptions, fn] = args.length === 3 ? args : [args[0], {}, args[1]]; | ||
return { pattern, providedOptions, fn }; | ||
} |
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,6 @@ | ||
@bar | ||
Feature: feature bar | ||
|
||
Scenario: scenario for bar | ||
Given step without tags | ||
Given step bound to feature |
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,11 @@ | ||
Feature: feature baz | ||
|
||
@baz1 | ||
Scenario: scenario for baz 1 | ||
Given step without tags | ||
Given step bound to scenario | ||
|
||
@baz2 | ||
Scenario: scenario for baz 2 | ||
Given step without tags | ||
Given step bound to scenario |
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,6 @@ | ||
@foo | ||
Feature: feature foo | ||
|
||
Scenario: scenario for foo | ||
Given step without tags | ||
Given step bound to feature |
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,24 @@ | ||
import { createBdd } from 'playwright-bdd'; | ||
|
||
const { Given } = createBdd(); | ||
const logger = console; | ||
|
||
Given('step without tags', async ({ $testInfo }) => { | ||
logger.log(`running step without tags: ${$testInfo.title}`); | ||
}); | ||
|
||
Given('step bound to feature', { tags: '@foo' }, async ({ $testInfo }) => { | ||
logger.log(`running step for @foo: ${$testInfo.title}`); | ||
}); | ||
|
||
Given('step bound to feature', { tags: '@bar' }, async ({ $testInfo }) => { | ||
logger.log(`running step for @bar: ${$testInfo.title}`); | ||
}); | ||
|
||
Given('step bound to scenario', { tags: '@baz1' }, async ({ $testInfo }) => { | ||
logger.log(`running step for @baz1: ${$testInfo.title}`); | ||
}); | ||
|
||
Given('step bound to scenario', { tags: '@baz2' }, async ({ $testInfo }) => { | ||
logger.log(`running step for @baz2: ${$testInfo.title}`); | ||
}); |
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,3 @@ | ||
{ | ||
"description": "This file is required for Playwright to consider this dir as a <package-json dir>. It ensures to load 'playwright-bdd' from './test/node_modules/playwright-bdd' and output './test-results' here to avoid conflicts." | ||
} |
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,10 @@ | ||
import { defineConfig } from '@playwright/test'; | ||
import { defineBddConfig } from 'playwright-bdd'; | ||
|
||
const testDir = defineBddConfig({ | ||
featuresRoot: 'features', | ||
}); | ||
|
||
export default defineConfig({ | ||
testDir, | ||
}); |
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,18 @@ | ||
import { test, expect, TestDir, execPlaywrightTest } from '../_helpers/index.mjs'; | ||
|
||
const testDir = new TestDir(import.meta); | ||
|
||
test(testDir.name, () => { | ||
const stdout = execPlaywrightTest(testDir.name); | ||
|
||
expect(stdout).toContain('running step for @foo: scenario for foo'); | ||
expect(stdout).toContain('running step for @bar: scenario for bar'); | ||
|
||
expect(stdout).toContain('running step for @baz1: scenario for baz 1'); | ||
expect(stdout).toContain('running step for @baz2: scenario for baz 2'); | ||
|
||
expect(stdout).toContain('running step without tags: scenario for foo'); | ||
expect(stdout).toContain('running step without tags: scenario for bar'); | ||
expect(stdout).toContain('running step without tags: scenario for baz 1'); | ||
expect(stdout).toContain('running step without tags: scenario for baz 2'); | ||
}); |