@qavajs/playwright-runner-adapter 0.6.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,24 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
|
|
|
10
10
|
:pencil: - chore
|
|
11
11
|
:microscope: - experimental
|
|
12
12
|
|
|
13
|
+
## [1.0.0]
|
|
14
|
+
- :rocket: added `executeStep` method to world to execute step definitions programmatically
|
|
15
|
+
```typescript
|
|
16
|
+
When('I do smth complex', async function() {
|
|
17
|
+
await this.executeStep(`I type 'username' to 'Username Input'`);
|
|
18
|
+
await this.executeStep(`I type 'password' to 'Password Input'`);
|
|
19
|
+
await this.executeStep(`I click 'Login Button'`);
|
|
20
|
+
await this.executeStep(`I fill following fields`, new DataTable([
|
|
21
|
+
[ 'Order', '123' ],
|
|
22
|
+
[ 'Delivery Location', 'New York' ]
|
|
23
|
+
]))
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
- :rocket: added reference to supportCodeLibrary to cucumber world
|
|
27
|
+
|
|
28
|
+
## [0.7.0]
|
|
29
|
+
- :rocket: added support of named hooks
|
|
30
|
+
|
|
13
31
|
## [0.6.1]
|
|
14
32
|
- :beetle: make params in hooks closer to cucumber types
|
|
15
33
|
|
|
@@ -17,6 +17,22 @@ class PlaywrightWorld {
|
|
|
17
17
|
this.log = options.log;
|
|
18
18
|
this.attach = options.attach;
|
|
19
19
|
this.parameters = options.parameters;
|
|
20
|
+
this.supportCodeLibrary = options.supportCodeLibrary;
|
|
21
|
+
}
|
|
22
|
+
async executeStep(text, extraParam) {
|
|
23
|
+
const steps = this.supportCodeLibrary.stepDefinitions.filter((s) => s.matchesStepName(text));
|
|
24
|
+
if (steps.length === 0)
|
|
25
|
+
throw new Error(`Step "${text}" is not defined`);
|
|
26
|
+
if (steps.length > 1)
|
|
27
|
+
throw new Error(`Step "${text}" matches multiple step definitions`);
|
|
28
|
+
const step = steps.pop();
|
|
29
|
+
const { parameters } = await step.getInvocationParameters({ step: { text }, world: this });
|
|
30
|
+
try {
|
|
31
|
+
await step.code.apply(this, [...parameters, extraParam]);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw new Error(`${text}\n${err}`);
|
|
35
|
+
}
|
|
20
36
|
}
|
|
21
37
|
}
|
|
22
38
|
exports.PlaywrightWorld = PlaywrightWorld;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlaywrightWorld.js","sourceRoot":"","sources":["../src/PlaywrightWorld.ts"],"names":[],"mappings":";;;AAAA,2CAAkG;AAElG;;GAEG;AACH,MAAa,eAAe;
|
|
1
|
+
{"version":3,"file":"PlaywrightWorld.js","sourceRoot":"","sources":["../src/PlaywrightWorld.ts"],"names":[],"mappings":";;;AAAA,2CAAkG;AAElG;;GAEG;AACH,MAAa,eAAe;IAaxB,YAAY,OAAY;QAJxB,SAAI,GAAG,WAAI,CAAC;QACZ,WAAM,GAAG,aAAM,CAAC;QAUhB,SAAI,GAAiC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAA6D,EAAE,EAAE;YAC3H,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC,CAAA;QAVG,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IACzD,CAAC;IAQD,KAAK,CAAC,WAAW,CAAY,IAAY,EAAE,UAAgB;QACvD,MAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAClG,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAAC;QACzE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,qCAAqC,CAAC,CAAC;QAC1F,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAS,CAAC;QAChC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAS,CAAC,CAAC;QAClG,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;QAC7D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,GAAG,EAAE,CAAC,CAAC;QACvC,CAAC;IACL,CAAC;CACJ;AAtCD,0CAsCC"}
|
package/adapter/adapter.spec.js
CHANGED
|
@@ -23,16 +23,19 @@ for (const feature of features) {
|
|
|
23
23
|
}
|
|
24
24
|
const world = new supportCodeLibrary.World({
|
|
25
25
|
log,
|
|
26
|
-
attach
|
|
26
|
+
attach,
|
|
27
|
+
supportCodeLibrary
|
|
27
28
|
});
|
|
28
29
|
test.beforeEach(world.init);
|
|
29
30
|
for (const testCase of tests) {
|
|
30
31
|
const tag = testCase.tags.map((tag) => tag.name);
|
|
31
32
|
test(testCase.name, { tag }, async () => {
|
|
33
|
+
var _a, _b;
|
|
32
34
|
const result = { status: 'passed' };
|
|
33
35
|
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
34
36
|
if (beforeHook.appliesToTestCase(testCase)) {
|
|
35
|
-
|
|
37
|
+
const hookName = (_a = beforeHook.name) !== null && _a !== void 0 ? _a : 'Before';
|
|
38
|
+
await test.step(hookName, async () => {
|
|
36
39
|
await beforeHook.code.apply(world, [{
|
|
37
40
|
pickle: testCase
|
|
38
41
|
}]);
|
|
@@ -85,7 +88,8 @@ for (const feature of features) {
|
|
|
85
88
|
}
|
|
86
89
|
for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
|
|
87
90
|
if (afterHook.appliesToTestCase(testCase)) {
|
|
88
|
-
|
|
91
|
+
const hookName = (_b = afterHook.name) !== null && _b !== void 0 ? _b : 'After';
|
|
92
|
+
await test.step(hookName, async () => {
|
|
89
93
|
await afterHook.code.apply(world, [{
|
|
90
94
|
pickle: testCase, result
|
|
91
95
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.spec.js","sourceRoot":"","sources":["../src/adapter.spec.ts"],"names":[],"mappings":";;AAAA,qCAAgC;AAEhC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,GAAG,IAAA,aAAI,GAAE,CAAC;AAEhD,SAAS,GAAG,CAAC,IAAS;IAClB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,MAAM,CAAsB,IAAS,EAAE,OAAY;;IACxD,MAAM,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,YAAY,CAAC;IAClD,MAAM,WAAW,GAAG,MAAA,OAAO,CAAC,SAAS,mCAAI,YAAY,CAAC;IACtD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACjD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,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AC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qavajs/playwright-runner-adapter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "adapter for playwright test runner",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"glob": "^11.0.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@cucumber/cucumber": "^11.0
|
|
18
|
-
"@playwright/test": "^1.
|
|
19
|
-
"@types/node": "^22.
|
|
20
|
-
"typescript": "^5.
|
|
17
|
+
"@cucumber/cucumber": "^11.1.0",
|
|
18
|
+
"@playwright/test": "^1.49.0",
|
|
19
|
+
"@types/node": "^22.10.1",
|
|
20
|
+
"typescript": "^5.7.2"
|
|
21
21
|
}
|
|
22
22
|
}
|
package/src/PlaywrightWorld.ts
CHANGED
|
@@ -14,11 +14,13 @@ export class PlaywrightWorld {
|
|
|
14
14
|
parameters!: string;
|
|
15
15
|
test = test;
|
|
16
16
|
expect = expect;
|
|
17
|
+
supportCodeLibrary!: any;
|
|
17
18
|
|
|
18
19
|
constructor(options: any) {
|
|
19
20
|
this.log = options.log;
|
|
20
21
|
this.attach = options.attach;
|
|
21
22
|
this.parameters = options.parameters;
|
|
23
|
+
this.supportCodeLibrary = options.supportCodeLibrary;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
init: ({ [fixture: string]: any }) = ({ browser, context, page }: { browser: Browser, context: BrowserContext, page: Page }) => {
|
|
@@ -26,4 +28,17 @@ export class PlaywrightWorld {
|
|
|
26
28
|
this.context = context;
|
|
27
29
|
this.page = page;
|
|
28
30
|
}
|
|
31
|
+
|
|
32
|
+
async executeStep(this: any, text: string, extraParam?: any) {
|
|
33
|
+
const steps = this.supportCodeLibrary.stepDefinitions.filter((s: any) => s.matchesStepName(text));
|
|
34
|
+
if (steps.length === 0) throw new Error(`Step "${text}" is not defined`);
|
|
35
|
+
if (steps.length > 1) throw new Error(`Step "${text}" matches multiple step definitions`);
|
|
36
|
+
const step = steps.pop() as any;
|
|
37
|
+
const { parameters } = await step.getInvocationParameters({ step: { text }, world: this } as any);
|
|
38
|
+
try {
|
|
39
|
+
await step.code.apply(this, [...parameters, extraParam]);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
throw new Error(`${text}\n${err}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
29
44
|
}
|
package/src/adapter.spec.ts
CHANGED
|
@@ -26,7 +26,8 @@ for (const feature of features) {
|
|
|
26
26
|
|
|
27
27
|
const world = new supportCodeLibrary.World({
|
|
28
28
|
log,
|
|
29
|
-
attach
|
|
29
|
+
attach,
|
|
30
|
+
supportCodeLibrary
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
test.beforeEach(world.init);
|
|
@@ -37,7 +38,8 @@ for (const feature of features) {
|
|
|
37
38
|
const result: { status: string, error?: any } = { status: 'passed' };
|
|
38
39
|
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
39
40
|
if (beforeHook.appliesToTestCase(testCase)) {
|
|
40
|
-
|
|
41
|
+
const hookName = beforeHook.name ?? 'Before';
|
|
42
|
+
await test.step(hookName, async () => {
|
|
41
43
|
await beforeHook.code.apply(world, [{
|
|
42
44
|
pickle: testCase
|
|
43
45
|
}]);
|
|
@@ -86,7 +88,8 @@ for (const feature of features) {
|
|
|
86
88
|
}
|
|
87
89
|
for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
|
|
88
90
|
if (afterHook.appliesToTestCase(testCase)) {
|
|
89
|
-
|
|
91
|
+
const hookName = afterHook.name ?? 'After';
|
|
92
|
+
await test.step(hookName, async () => {
|
|
90
93
|
await afterHook.code.apply(world, [{
|
|
91
94
|
pickle: testCase, result
|
|
92
95
|
}]);
|