@qavajs/playwright-runner-adapter 2.1.0 → 2.3.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 +7 -0
- package/adapter/PlaywrightWorld.d.ts +1 -1
- package/adapter/PlaywrightWorld.js +3 -1
- package/adapter/PlaywrightWorld.js.map +1 -1
- package/adapter/cucumberAdapter.js +130 -164
- package/adapter/cucumberAdapter.js.map +1 -1
- package/adapter/js/PlaywrightWorld.d.ts +31 -0
- package/adapter/js/PlaywrightWorld.js +56 -0
- package/adapter/js/Template.d.ts +10 -0
- package/adapter/js/Template.js +26 -0
- package/adapter/js/cucumberAdapter.d.ts +4 -0
- package/adapter/js/cucumberAdapter.js +244 -0
- package/adapter/js/filter.d.ts +19 -0
- package/adapter/js/filter.js +55 -0
- package/adapter/js/index.d.ts +5 -0
- package/adapter/js/index.js +21 -0
- package/adapter/js/loader.d.ts +14 -0
- package/adapter/js/loader.js +62 -0
- package/package.json +6 -6
- package/src/PlaywrightWorld.ts +4 -2
- package/src/cucumberAdapter.ts +216 -210
- package/tsconfig.js.json +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,13 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
|
|
|
14
14
|
|
|
15
15
|
:microscope: - experimental
|
|
16
16
|
|
|
17
|
+
## [2.3.0]
|
|
18
|
+
- :rocket: simplified adapter by moving hook into test
|
|
19
|
+
|
|
20
|
+
## [2.2.0]
|
|
21
|
+
- :rocket: added `request` into default fixture import
|
|
22
|
+
- :beetle: fixed `attach` method type
|
|
23
|
+
|
|
17
24
|
## [2.1.0]
|
|
18
25
|
- :rocket: made declaration of beforeAll/afterAll hooks optional to enable pure parallelism
|
|
19
26
|
|
|
@@ -18,6 +18,7 @@ class TestWorld {
|
|
|
18
18
|
this.attach = options.attach;
|
|
19
19
|
this.parameters = options.parameters;
|
|
20
20
|
this.supportCodeLibrary = options.supportCodeLibrary;
|
|
21
|
+
this.config = options.config;
|
|
21
22
|
}
|
|
22
23
|
async executeStep(text, extraParam) {
|
|
23
24
|
const steps = this.supportCodeLibrary.stepDefinitions.filter((s) => s.matchesStepName(text));
|
|
@@ -45,10 +46,11 @@ class PlaywrightWorld extends TestWorld {
|
|
|
45
46
|
browser;
|
|
46
47
|
browserName;
|
|
47
48
|
request;
|
|
48
|
-
init = ({ browser, context, page }) => {
|
|
49
|
+
init = ({ browser, context, page, request }) => {
|
|
49
50
|
this.browser = browser;
|
|
50
51
|
this.context = context;
|
|
51
52
|
this.page = page;
|
|
53
|
+
this.request = request;
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
exports.PlaywrightWorld = PlaywrightWorld;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlaywrightWorld.js","sourceRoot":"","sources":["../src/PlaywrightWorld.ts"],"names":[],"mappings":";;;AAAA,2CAAkG;AAElG;;GAEG;AACH,MAAa,SAAS;IAClB,GAAG,CAAuB;IAC1B,MAAM,
|
|
1
|
+
{"version":3,"file":"PlaywrightWorld.js","sourceRoot":"","sources":["../src/PlaywrightWorld.ts"],"names":[],"mappings":";;;AAAA,2CAAkG;AAElG;;GAEG;AACH,MAAa,SAAS;IAClB,GAAG,CAAuB;IAC1B,MAAM,CAAoF;IAC1F,UAAU,CAAU;IACpB,MAAM,CAAM;IACZ,kBAAkB,CAAO;IACzB,IAAI,GAAG,WAAI,CAAC;IACZ,MAAM,GAAG,aAAM,CAAC;IAEhB,YAAY,OAAY;QACpB,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;QACrD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACjC,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AAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC,CAAA;CACJ;AAbD,0CAaC"}
|
|
@@ -4,7 +4,6 @@ exports.defineConfig = defineConfig;
|
|
|
4
4
|
const loader_1 = require("./loader");
|
|
5
5
|
// Constants
|
|
6
6
|
const ANNOTATION_TYPES = {
|
|
7
|
-
TEST_ID: 'testId',
|
|
8
7
|
NAME: 'name',
|
|
9
8
|
URI: 'uri',
|
|
10
9
|
TAGS: 'tags'
|
|
@@ -31,31 +30,6 @@ const STEP_ARGUMENT_LABELS = {
|
|
|
31
30
|
DOC_STRING: ' [MultiLine]',
|
|
32
31
|
DATA_TABLE: ' [DataTable]'
|
|
33
32
|
};
|
|
34
|
-
/**
|
|
35
|
-
* Extracts the test ID from TestInfo annotations
|
|
36
|
-
*/
|
|
37
|
-
function getTestId(testInfo) {
|
|
38
|
-
const annotation = testInfo.annotations
|
|
39
|
-
.find((annotation) => annotation.type === ANNOTATION_TYPES.TEST_ID);
|
|
40
|
-
if (!annotation?.description) {
|
|
41
|
-
throw new Error('Test ID annotation not found');
|
|
42
|
-
}
|
|
43
|
-
return annotation.description;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Converts TestInfo to HookResult format
|
|
47
|
-
*/
|
|
48
|
-
function getResult(testInfo) {
|
|
49
|
-
const message = testInfo.errors.length > 0
|
|
50
|
-
? testInfo.errors.map((err) => err.message).join('\n')
|
|
51
|
-
: undefined;
|
|
52
|
-
return {
|
|
53
|
-
duration: testInfo.duration,
|
|
54
|
-
message,
|
|
55
|
-
status: testInfo.status?.toUpperCase() ?? 'UNKNOWN',
|
|
56
|
-
exception: testInfo.error
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
33
|
/**
|
|
60
34
|
* Creates a location object from step definition
|
|
61
35
|
*/
|
|
@@ -80,7 +54,7 @@ function log(data) {
|
|
|
80
54
|
function attach(body, details) {
|
|
81
55
|
const fileName = details?.fileName ?? DEFAULT_VALUES.ATTACHMENT_FILENAME;
|
|
82
56
|
const contentType = details?.mediaType ?? DEFAULT_VALUES.CONTENT_TYPE;
|
|
83
|
-
this.test.info().attach(fileName, { body, contentType });
|
|
57
|
+
return this.test.info().attach(fileName, { body, contentType });
|
|
84
58
|
}
|
|
85
59
|
/**
|
|
86
60
|
* Generates a human-readable step name with argument type indicator
|
|
@@ -94,6 +68,85 @@ function stepName(pickleStep) {
|
|
|
94
68
|
}
|
|
95
69
|
return step;
|
|
96
70
|
}
|
|
71
|
+
function createTestExecutionResult() {
|
|
72
|
+
return {
|
|
73
|
+
status: 'passed',
|
|
74
|
+
start: Date.now()
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function createHookResult(result) {
|
|
78
|
+
return {
|
|
79
|
+
duration: (Date.now() - result.start),
|
|
80
|
+
message: result.error?.message,
|
|
81
|
+
status: result.status.toUpperCase(),
|
|
82
|
+
exception: result.error
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function createScenarioAnnotation(testCase) {
|
|
86
|
+
const tag = [...new Set(testCase.tags.map((item) => item.name))];
|
|
87
|
+
return [
|
|
88
|
+
{ type: ANNOTATION_TYPES.NAME, description: testCase.name },
|
|
89
|
+
{ type: ANNOTATION_TYPES.URI, description: testCase.uri },
|
|
90
|
+
{ type: ANNOTATION_TYPES.TAGS, description: JSON.stringify(tag) }
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
function createScenarioTags(testCase) {
|
|
94
|
+
return [...new Set(testCase.tags.map((item) => item.name))];
|
|
95
|
+
}
|
|
96
|
+
function createCaseHookPayload(feature, testCase) {
|
|
97
|
+
return {
|
|
98
|
+
gherkinDocument: feature.gherkinDocument,
|
|
99
|
+
pickle: testCase
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function executeCaseHooks(test, hooks, world, testCase, defaultHookName, createPayload) {
|
|
103
|
+
for (const hook of hooks) {
|
|
104
|
+
if (!hook.appliesToTestCase(testCase)) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const hookName = hook.name ?? defaultHookName;
|
|
108
|
+
const location = getLine(hook);
|
|
109
|
+
await test.step(hookName, () => hook.code.apply(world, [createPayload(hook)]), location);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function executeStepHooks(test, hooks, world, testCase, hookName, createPayload) {
|
|
113
|
+
for (const hook of hooks) {
|
|
114
|
+
if (!hook.appliesToTestCase(testCase)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const location = getLine(hook);
|
|
118
|
+
await test.step(hookName, () => hook.code.apply(world, [createPayload(hook)]), location);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function createStepHookParameter(feature, testCase, pickleStep, result) {
|
|
122
|
+
return {
|
|
123
|
+
gherkinDocument: feature.gherkinDocument,
|
|
124
|
+
testCaseStartedId: DEFAULT_VALUES.TEST_CASE_ID,
|
|
125
|
+
testStepId: DEFAULT_VALUES.TEST_STEP_ID,
|
|
126
|
+
pickle: testCase,
|
|
127
|
+
pickleStep,
|
|
128
|
+
result: createHookResult(result)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function createCaseHookParameter(feature, testCase, result) {
|
|
132
|
+
return {
|
|
133
|
+
gherkinDocument: feature.gherkinDocument,
|
|
134
|
+
testCaseStartedId: DEFAULT_VALUES.TEST_CASE_ID,
|
|
135
|
+
pickle: testCase,
|
|
136
|
+
result: createHookResult(result)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function findSingleStepDefinition(supportCodeLibrary, pickleStep) {
|
|
140
|
+
const matchingSteps = supportCodeLibrary.stepDefinitions
|
|
141
|
+
.filter((stepDefinition) => stepDefinition.matchesStepName(pickleStep.text));
|
|
142
|
+
if (matchingSteps.length === 0) {
|
|
143
|
+
throw new Error(`Step '${pickleStep.text}' is not defined`);
|
|
144
|
+
}
|
|
145
|
+
if (matchingSteps.length > 1) {
|
|
146
|
+
throw new Error(`Step '${pickleStep.text}' matches multiple step definitions`);
|
|
147
|
+
}
|
|
148
|
+
return matchingSteps[0];
|
|
149
|
+
}
|
|
97
150
|
/**
|
|
98
151
|
* Executes before all hooks
|
|
99
152
|
*/
|
|
@@ -120,18 +173,6 @@ function executeAfterAllHooks(test, hooks) {
|
|
|
120
173
|
}
|
|
121
174
|
});
|
|
122
175
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Creates test annotations from test case data
|
|
125
|
-
*/
|
|
126
|
-
function createTestAnnotations(testCase) {
|
|
127
|
-
const tags = [...new Set(testCase.tags.map((tag) => tag.name))];
|
|
128
|
-
return [
|
|
129
|
-
{ type: ANNOTATION_TYPES.NAME, description: testCase.name },
|
|
130
|
-
{ type: ANNOTATION_TYPES.URI, description: testCase.uri },
|
|
131
|
-
{ type: ANNOTATION_TYPES.TEST_ID, description: testCase.id },
|
|
132
|
-
{ type: ANNOTATION_TYPES.TAGS, description: JSON.stringify(tags) }
|
|
133
|
-
];
|
|
134
|
-
}
|
|
135
176
|
/**
|
|
136
177
|
* Main configuration function that sets up Cucumber adapter for Playwright
|
|
137
178
|
*/
|
|
@@ -140,138 +181,63 @@ function defineConfig(config) {
|
|
|
140
181
|
const fixture = new supportCodeLibrary.World({ config });
|
|
141
182
|
const test = fixture.test;
|
|
142
183
|
executeBeforeAllHooks(test, supportCodeLibrary.beforeTestRunHookDefinitions);
|
|
143
|
-
const worlds = new Map();
|
|
144
184
|
for (const feature of features) {
|
|
145
185
|
const tests = feature.tests;
|
|
146
|
-
test.describe(feature.feature,
|
|
147
|
-
/**
|
|
148
|
-
* Factory function to create and register world instances
|
|
149
|
-
*/
|
|
150
|
-
const worldFactory = (fixtures) => {
|
|
151
|
-
const world = new supportCodeLibrary.World({
|
|
152
|
-
log,
|
|
153
|
-
attach,
|
|
154
|
-
supportCodeLibrary,
|
|
155
|
-
config
|
|
156
|
-
});
|
|
157
|
-
world.init(fixtures);
|
|
158
|
-
worlds.set(getTestId(test.info()), world);
|
|
159
|
-
};
|
|
160
|
-
worldFactory.toString = () => fixture.init.toString();
|
|
161
|
-
test.beforeEach(HOOK_NAMES.WORLD, worldFactory);
|
|
162
|
-
test.beforeEach(HOOK_NAMES.BEFORE_HOOKS, async () => {
|
|
163
|
-
const testId = getTestId(test.info());
|
|
164
|
-
const world = worlds.get(testId);
|
|
165
|
-
const testCase = tests.find((t) => t.id === testId);
|
|
166
|
-
if (!testCase) {
|
|
167
|
-
throw new Error(`Test case with ID ${testId} not found`);
|
|
168
|
-
}
|
|
169
|
-
for (const beforeHook of supportCodeLibrary.beforeTestCaseHookDefinitions) {
|
|
170
|
-
if (beforeHook.appliesToTestCase(testCase)) {
|
|
171
|
-
const hookName = beforeHook.name ?? HOOK_NAMES.BEFORE;
|
|
172
|
-
const location = getLine(beforeHook);
|
|
173
|
-
await test.step(hookName, () => beforeHook.code.apply(world, [{
|
|
174
|
-
gherkinDocument: feature.gherkinDocument,
|
|
175
|
-
pickle: testCase
|
|
176
|
-
}]), location);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
});
|
|
186
|
+
test.describe(feature.feature, () => {
|
|
180
187
|
for (const testCase of tests) {
|
|
181
|
-
const tag =
|
|
182
|
-
const annotation =
|
|
183
|
-
|
|
184
|
-
const world =
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
const [step] = matchingSteps;
|
|
199
|
-
const location = getLine(step);
|
|
200
|
-
await test.step(stepName(pickleStep), async () => {
|
|
201
|
-
for (const beforeStep of supportCodeLibrary.beforeTestStepHookDefinitions) {
|
|
202
|
-
if (beforeStep.appliesToTestCase(testCase)) {
|
|
203
|
-
const location = getLine(beforeStep);
|
|
204
|
-
await test.step(HOOK_NAMES.BEFORE_STEP, () => beforeStep.code.apply(world, [{
|
|
205
|
-
gherkinDocument: feature.gherkinDocument,
|
|
206
|
-
pickle: testCase,
|
|
207
|
-
pickleStep
|
|
208
|
-
}]), location);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
const { parameters } = await step.getInvocationParameters({
|
|
212
|
-
step: {
|
|
213
|
-
text: pickleStep.text,
|
|
214
|
-
argument: pickleStep.argument
|
|
215
|
-
},
|
|
216
|
-
world
|
|
217
|
-
});
|
|
218
|
-
try {
|
|
219
|
-
await step.code.apply(world, parameters);
|
|
188
|
+
const tag = createScenarioTags(testCase);
|
|
189
|
+
const annotation = createScenarioAnnotation(testCase);
|
|
190
|
+
const testBody = async (fixtures) => {
|
|
191
|
+
const world = new supportCodeLibrary.World({
|
|
192
|
+
log,
|
|
193
|
+
attach,
|
|
194
|
+
supportCodeLibrary,
|
|
195
|
+
config
|
|
196
|
+
});
|
|
197
|
+
world.init(fixtures);
|
|
198
|
+
const result = createTestExecutionResult();
|
|
199
|
+
await executeCaseHooks(test, supportCodeLibrary.beforeTestCaseHookDefinitions, world, testCase, HOOK_NAMES.BEFORE, () => createCaseHookPayload(feature, testCase));
|
|
200
|
+
try {
|
|
201
|
+
for (const pickleStep of testCase.steps) {
|
|
202
|
+
if (result.status !== 'passed') {
|
|
203
|
+
break;
|
|
220
204
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
message: result.error?.message,
|
|
239
|
-
status: result.status.toUpperCase(),
|
|
240
|
-
exception: result.error
|
|
241
|
-
}
|
|
242
|
-
}]), location);
|
|
243
|
-
}
|
|
205
|
+
const step = findSingleStepDefinition(supportCodeLibrary, pickleStep);
|
|
206
|
+
const location = getLine(step);
|
|
207
|
+
await test.step(stepName(pickleStep), async () => {
|
|
208
|
+
await executeStepHooks(test, supportCodeLibrary.beforeTestStepHookDefinitions, world, testCase, HOOK_NAMES.BEFORE_STEP, () => ({
|
|
209
|
+
gherkinDocument: feature.gherkinDocument,
|
|
210
|
+
pickle: testCase,
|
|
211
|
+
pickleStep
|
|
212
|
+
}));
|
|
213
|
+
const { parameters } = await step.getInvocationParameters({
|
|
214
|
+
step: {
|
|
215
|
+
text: pickleStep.text,
|
|
216
|
+
argument: pickleStep.argument
|
|
217
|
+
},
|
|
218
|
+
world
|
|
219
|
+
});
|
|
220
|
+
try {
|
|
221
|
+
await step.code.apply(world, parameters);
|
|
244
222
|
}
|
|
245
|
-
|
|
246
|
-
|
|
223
|
+
catch (err) {
|
|
224
|
+
result.status = 'failed';
|
|
225
|
+
result.error = err;
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
finally {
|
|
229
|
+
await executeStepHooks(test, supportCodeLibrary.afterTestStepHookDefinitions, world, testCase, HOOK_NAMES.AFTER_STEP, () => createStepHookParameter(feature, testCase, pickleStep, result));
|
|
230
|
+
}
|
|
231
|
+
}, location);
|
|
232
|
+
}
|
|
247
233
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
test.afterEach(HOOK_NAMES.AFTER_HOOKS, async () => {
|
|
251
|
-
const testInfo = test.info();
|
|
252
|
-
const testId = getTestId(testInfo);
|
|
253
|
-
const world = worlds.get(testId);
|
|
254
|
-
const testCase = tests.find((t) => t.id === testId);
|
|
255
|
-
if (!testCase) {
|
|
256
|
-
throw new Error(`Test case with ID ${testId} not found`);
|
|
257
|
-
}
|
|
258
|
-
for (const afterHook of supportCodeLibrary.afterTestCaseHookDefinitions) {
|
|
259
|
-
if (afterHook.appliesToTestCase(testCase)) {
|
|
260
|
-
const hookName = afterHook.name ?? HOOK_NAMES.AFTER;
|
|
261
|
-
const location = getLine(afterHook);
|
|
262
|
-
await test.step(hookName, () => afterHook.code.apply(world, [{
|
|
263
|
-
gherkinDocument: feature.gherkinDocument,
|
|
264
|
-
testCaseStartedId: DEFAULT_VALUES.TEST_CASE_ID,
|
|
265
|
-
pickle: testCase,
|
|
266
|
-
result: getResult(testInfo)
|
|
267
|
-
}]), location);
|
|
234
|
+
finally {
|
|
235
|
+
await executeCaseHooks(test, supportCodeLibrary.afterTestCaseHookDefinitions, world, testCase, HOOK_NAMES.AFTER, () => createCaseHookParameter(feature, testCase, result));
|
|
268
236
|
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
worlds.delete(testId);
|
|
274
|
-
});
|
|
237
|
+
};
|
|
238
|
+
testBody.toString = () => fixture.init.toString();
|
|
239
|
+
test(testCase.name, { tag, annotation }, testBody);
|
|
240
|
+
}
|
|
275
241
|
});
|
|
276
242
|
}
|
|
277
243
|
executeAfterAllHooks(test, supportCodeLibrary.afterTestRunHookDefinitions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cucumberAdapter.js","sourceRoot":"","sources":["../src/cucumberAdapter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"cucumberAdapter.js","sourceRoot":"","sources":["../src/cucumberAdapter.ts"],"names":[],"mappings":";;AAgSA,oCAmGC;AAnYD,qCAA8B;AAI9B,YAAY;AACZ,MAAM,gBAAgB,GAAG;IACrB,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,MAAM;CACN,CAAC;AAEX,MAAM,UAAU,GAAG;IACf,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;IAC1B,UAAU,EAAE,YAAY;IACxB,KAAK,EAAE,OAAO;IACd,YAAY,EAAE,cAAc;IAC5B,WAAW,EAAE,aAAa;CACpB,CAAC;AAEX,MAAM,cAAc,GAAG;IACnB,mBAAmB,EAAE,YAAY;IACjC,YAAY,EAAE,YAAY;IAC1B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|
+
/**
|
|
3
|
+
* Cucumber world for playwright adapter
|
|
4
|
+
*/
|
|
5
|
+
export declare class TestWorld {
|
|
6
|
+
log: (data: any) => void;
|
|
7
|
+
attach: (data: any, details?: {
|
|
8
|
+
fileName?: string;
|
|
9
|
+
mediaType: string;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
parameters: string;
|
|
12
|
+
config: any;
|
|
13
|
+
supportCodeLibrary: any;
|
|
14
|
+
test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
15
|
+
expect: import("@playwright/test").Expect<{}>;
|
|
16
|
+
constructor(options: any);
|
|
17
|
+
executeStep(this: any, text: string, extraParam?: any): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Cucumber Playwright world for playwright adapter
|
|
21
|
+
*/
|
|
22
|
+
export declare class PlaywrightWorld extends TestWorld {
|
|
23
|
+
page: Page;
|
|
24
|
+
context: BrowserContext;
|
|
25
|
+
browser: Browser;
|
|
26
|
+
browserName: string;
|
|
27
|
+
request: APIRequestContext;
|
|
28
|
+
init: ({
|
|
29
|
+
[fixture: string]: any;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlaywrightWorld = exports.TestWorld = void 0;
|
|
4
|
+
const test_1 = require("@playwright/test");
|
|
5
|
+
/**
|
|
6
|
+
* Cucumber world for playwright adapter
|
|
7
|
+
*/
|
|
8
|
+
class TestWorld {
|
|
9
|
+
log;
|
|
10
|
+
attach;
|
|
11
|
+
parameters;
|
|
12
|
+
config;
|
|
13
|
+
supportCodeLibrary;
|
|
14
|
+
test = test_1.test;
|
|
15
|
+
expect = test_1.expect;
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.log = options.log;
|
|
18
|
+
this.attach = options.attach;
|
|
19
|
+
this.parameters = options.parameters;
|
|
20
|
+
this.supportCodeLibrary = options.supportCodeLibrary;
|
|
21
|
+
this.config = options.config;
|
|
22
|
+
}
|
|
23
|
+
async executeStep(text, extraParam) {
|
|
24
|
+
const steps = this.supportCodeLibrary.stepDefinitions.filter((s) => s.matchesStepName(text));
|
|
25
|
+
if (steps.length === 0)
|
|
26
|
+
throw new Error(`Step "${text}" is not defined`);
|
|
27
|
+
if (steps.length > 1)
|
|
28
|
+
throw new Error(`Step "${text}" matches multiple step definitions`);
|
|
29
|
+
const step = steps.pop();
|
|
30
|
+
const { parameters } = await step.getInvocationParameters({ step: { text }, world: this });
|
|
31
|
+
try {
|
|
32
|
+
await step.code.apply(this, [...parameters, extraParam]);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
throw new Error(`${text}\n${err}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.TestWorld = TestWorld;
|
|
40
|
+
/**
|
|
41
|
+
* Cucumber Playwright world for playwright adapter
|
|
42
|
+
*/
|
|
43
|
+
class PlaywrightWorld extends TestWorld {
|
|
44
|
+
page;
|
|
45
|
+
context;
|
|
46
|
+
browser;
|
|
47
|
+
browserName;
|
|
48
|
+
request;
|
|
49
|
+
init = ({ browser, context, page, request }) => {
|
|
50
|
+
this.browser = browser;
|
|
51
|
+
this.context = context;
|
|
52
|
+
this.page = page;
|
|
53
|
+
this.request = request;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.PlaywrightWorld = PlaywrightWorld;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define template step
|
|
3
|
+
* @param {string} scenario - multiline string with steps
|
|
4
|
+
* @example
|
|
5
|
+
* When('I click {string} and verify {string}', Template((locator, expected) => `
|
|
6
|
+
* I click '${locator}'
|
|
7
|
+
* I expect '${locator} > Value' to equal '${expected}'
|
|
8
|
+
* `));
|
|
9
|
+
*/
|
|
10
|
+
export declare function Template(scenario: (...args: any[]) => string): (...args: string[]) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Template = Template;
|
|
4
|
+
/**
|
|
5
|
+
* Define template step
|
|
6
|
+
* @param {string} scenario - multiline string with steps
|
|
7
|
+
* @example
|
|
8
|
+
* When('I click {string} and verify {string}', Template((locator, expected) => `
|
|
9
|
+
* I click '${locator}'
|
|
10
|
+
* I expect '${locator} > Value' to equal '${expected}'
|
|
11
|
+
* `));
|
|
12
|
+
*/
|
|
13
|
+
function Template(scenario) {
|
|
14
|
+
return new Proxy(scenario, {
|
|
15
|
+
apply: async function (template, world, args) {
|
|
16
|
+
const scenario = template(...args);
|
|
17
|
+
const steps = scenario
|
|
18
|
+
.split('\n')
|
|
19
|
+
.map(step => step.trim())
|
|
20
|
+
.filter(Boolean);
|
|
21
|
+
for (const step of steps) {
|
|
22
|
+
await world.executeStep(step);
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|