@zohodesk/testinglibrary 0.1.9-exp-actors → 0.2.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/build/bdd-framework/cli/commands/env.js +1 -1
- package/build/bdd-framework/cli/commands/export.js +18 -3
- package/build/bdd-framework/decorators.js +2 -2
- package/build/bdd-framework/gen/formatter.js +57 -13
- package/build/bdd-framework/gen/index.js +21 -9
- package/build/bdd-framework/gen/specialTags.js +70 -0
- package/build/bdd-framework/gen/testFile.js +10 -5
- package/build/bdd-framework/gen/testNode.js +4 -29
- package/build/bdd-framework/gen/testPoms.js +1 -1
- package/build/bdd-framework/index.js +1 -1
- package/build/bdd-framework/playwright/testTypeImpl.js +28 -10
- package/build/bdd-framework/playwright/types.js +8 -1
- package/build/bdd-framework/playwright/utils.js +22 -0
- package/build/bdd-framework/reporter/cucumber/base.js +2 -7
- package/build/bdd-framework/reporter/cucumber/html.js +9 -4
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/AttachmentMapper.js +28 -10
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Builder.js +21 -20
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/Hook.js +3 -3
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRun.js +46 -18
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestCaseRunHooks.js +41 -20
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepAttachments.js +19 -2
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/TestStepRun.js +42 -16
- package/build/bdd-framework/reporter/cucumber/messagesBuilder/{pwUtils.js → pwStepUtils.js} +33 -14
- package/build/bdd-framework/run/StepInvoker.js +8 -7
- package/build/bdd-framework/run/bddData/index.js +59 -0
- package/build/bdd-framework/run/bddData/types.js +5 -0
- package/build/bdd-framework/run/bddFixtures.js +5 -4
- package/build/bdd-framework/run/bddWorld.js +3 -3
- package/build/bdd-framework/run/bddWorldInternal.js +1 -5
- package/build/bdd-framework/snippets/index.js +1 -1
- package/build/bdd-framework/steps/createBdd.js +78 -0
- package/build/bdd-framework/steps/decorators/class.js +68 -0
- package/build/bdd-framework/steps/decorators/steps.js +98 -0
- package/build/bdd-framework/steps/defineStep.js +62 -0
- package/build/bdd-framework/steps/stepConfig.js +24 -0
- package/build/core/playwright/env-initializer.js +17 -2
- package/build/core/playwright/helpers/configFileNameProvider.js +1 -0
- package/build/core/playwright/index.js +14 -71
- package/build/core/playwright/readConfigFile.js +13 -2
- package/build/index.d.ts +2 -21
- package/changelog.md +14 -0
- package/npm-shrinkwrap.json +1 -1
- package/package.json +3 -2
- package/build/bdd-framework/run/bddDataAttachment.js +0 -46
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BddDataManager = void 0;
|
|
7
|
+
exports.getBddDataFromTest = getBddDataFromTest;
|
|
8
|
+
var _createTestStep = require("../../cucumber/createTestStep");
|
|
9
|
+
var _utils = require("../../utils");
|
|
10
|
+
var _utils2 = require("../../playwright/utils");
|
|
11
|
+
const BDD_DATA_ANNOTATION_NAME = '__bddData';
|
|
12
|
+
class BddDataManager {
|
|
13
|
+
testInfo;
|
|
14
|
+
data;
|
|
15
|
+
constructor(testInfo, testMeta, uri) {
|
|
16
|
+
this.testInfo = testInfo;
|
|
17
|
+
this.data = {
|
|
18
|
+
uri,
|
|
19
|
+
pickleLocation: testMeta.pickleLocation,
|
|
20
|
+
steps: []
|
|
21
|
+
};
|
|
22
|
+
this.save({
|
|
23
|
+
create: true
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
registerStep(stepDefinition, stepText, pwStepLocation) {
|
|
27
|
+
const step = (0, _createTestStep.createTestStep)(stepDefinition, stepText);
|
|
28
|
+
this.data.steps.push({
|
|
29
|
+
pwStepLocation: (0, _utils.stringifyLocation)(pwStepLocation),
|
|
30
|
+
stepMatchArgumentsLists: step.stepMatchArgumentsLists || []
|
|
31
|
+
});
|
|
32
|
+
this.save();
|
|
33
|
+
}
|
|
34
|
+
save({
|
|
35
|
+
create = false
|
|
36
|
+
} = {}) {
|
|
37
|
+
(0, _utils2.updateAnnotation)(this.testInfo, {
|
|
38
|
+
type: BDD_DATA_ANNOTATION_NAME,
|
|
39
|
+
description: JSON.stringify(this.data)
|
|
40
|
+
}, {
|
|
41
|
+
create
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.BddDataManager = BddDataManager;
|
|
46
|
+
function getBddDataFromTest({
|
|
47
|
+
annotations
|
|
48
|
+
}) {
|
|
49
|
+
const annotationIndex = annotations.findIndex(isBddDataAnnotation);
|
|
50
|
+
const annotation = annotations[annotationIndex];
|
|
51
|
+
const bddData = annotation !== null && annotation !== void 0 && annotation.description ? JSON.parse(annotation.description) : undefined;
|
|
52
|
+
return {
|
|
53
|
+
bddData,
|
|
54
|
+
annotationIndex
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function isBddDataAnnotation(annotation) {
|
|
58
|
+
return annotation.type === BDD_DATA_ANNOTATION_NAME;
|
|
59
|
+
}
|
|
@@ -11,7 +11,7 @@ var _loadSteps = require("../cucumber/loadSteps");
|
|
|
11
11
|
var _bddWorld = require("./bddWorld");
|
|
12
12
|
var _config = require("../config");
|
|
13
13
|
var _env = require("../config/env");
|
|
14
|
-
var _steps = require("../
|
|
14
|
+
var _steps = require("../steps/decorators/steps");
|
|
15
15
|
var _configDir = require("../config/configDir");
|
|
16
16
|
var _scenario = require("../hooks/scenario");
|
|
17
17
|
var _worker = require("../hooks/worker");
|
|
@@ -19,6 +19,7 @@ var _StepInvoker = require("./StepInvoker");
|
|
|
19
19
|
var _testMeta = require("../gen/testMeta");
|
|
20
20
|
var _logger = require("../utils/logger");
|
|
21
21
|
var _enrichReporterData = require("../config/enrichReporterData");
|
|
22
|
+
var _bddData = require("./bddData");
|
|
22
23
|
const test = exports.test = _test.test.extend({
|
|
23
24
|
// load cucumber once per worker (auto-fixture)
|
|
24
25
|
// todo: maybe remove caching in cucumber/loadConfig.ts and cucumber/loadSteps.ts
|
|
@@ -76,12 +77,12 @@ const test = exports.test = _test.test.extend({
|
|
|
76
77
|
log: () => _logger.logger.warn(`world.log() is noop, please use world.testInfo.attach()`),
|
|
77
78
|
attach: async () => _logger.logger.warn(`world.attach() is noop, please use world.testInfo.attach()`)
|
|
78
79
|
});
|
|
80
|
+
if ((0, _enrichReporterData.getEnrichReporterData)(config)) {
|
|
81
|
+
world.$internal.bddDataManager = new _bddData.BddDataManager(testInfo, $testMeta, $uri);
|
|
82
|
+
}
|
|
79
83
|
await world.init();
|
|
80
84
|
await use(world);
|
|
81
85
|
await world.destroy();
|
|
82
|
-
if ((0, _enrichReporterData.getEnrichReporterData)(config)) {
|
|
83
|
-
await world.$internal.bddData.attach($testMeta, $uri);
|
|
84
|
-
}
|
|
85
86
|
},
|
|
86
87
|
Given: ({
|
|
87
88
|
$bddWorld
|
|
@@ -9,15 +9,15 @@ var _cucumber = require("@cucumber/cucumber");
|
|
|
9
9
|
var _bddWorldInternal = require("./bddWorldInternal");
|
|
10
10
|
class BddWorld extends _cucumber.World {
|
|
11
11
|
options;
|
|
12
|
-
// special
|
|
12
|
+
// special namespace to hold internal bdd related methods, must be public.
|
|
13
13
|
$internal;
|
|
14
14
|
constructor(options) {
|
|
15
15
|
super(options);
|
|
16
16
|
this.options = options;
|
|
17
|
-
this.$internal = new _bddWorldInternal.BddWorldInternal(
|
|
17
|
+
this.$internal = new _bddWorldInternal.BddWorldInternal();
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Use
|
|
20
|
+
* Use custom fixture in cucumber-style steps.
|
|
21
21
|
*
|
|
22
22
|
* Note: TS does not support partial generic inference,
|
|
23
23
|
* that's why we can't use this.useFixture<typeof test>('xxx');
|
|
@@ -4,12 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BddWorldInternal = void 0;
|
|
7
|
-
var _bddDataAttachment = require("./bddDataAttachment");
|
|
8
7
|
class BddWorldInternal {
|
|
9
8
|
currentStepFixtures = {};
|
|
10
|
-
|
|
11
|
-
constructor(world) {
|
|
12
|
-
this.bddData = new _bddDataAttachment.BddData(world);
|
|
13
|
-
}
|
|
9
|
+
bddDataManager;
|
|
14
10
|
}
|
|
15
11
|
exports.BddWorldInternal = BddWorldInternal;
|
|
@@ -7,7 +7,7 @@ exports.Snippets = void 0;
|
|
|
7
7
|
var _url = require("url");
|
|
8
8
|
var _loadSnippetBuilder = require("../cucumber/loadSnippetBuilder");
|
|
9
9
|
var _logger = require("../utils/logger");
|
|
10
|
-
var _stepConfig = require("../
|
|
10
|
+
var _stepConfig = require("../steps/stepConfig");
|
|
11
11
|
/**
|
|
12
12
|
* Generate and show snippets for undefined steps
|
|
13
13
|
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createBdd = createBdd;
|
|
7
|
+
exports.hasCustomTest = void 0;
|
|
8
|
+
var _bddFixtures = require("../run/bddFixtures");
|
|
9
|
+
var _testTypeImpl = require("../playwright/testTypeImpl");
|
|
10
|
+
var _defineStep = require("./defineStep");
|
|
11
|
+
var _exit = require("../utils/exit");
|
|
12
|
+
var _scenario = require("../hooks/scenario");
|
|
13
|
+
var _worker = require("../hooks/worker");
|
|
14
|
+
var _fixtureParameterNames = require("../playwright/fixtureParameterNames");
|
|
15
|
+
/**
|
|
16
|
+
* Stuff related to writing steps in Playwright-style.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// Global flag showing that custom test was passed.
|
|
20
|
+
// Used when checking 'importTestFrom' config option.
|
|
21
|
+
// todo: https://github.com/vitalets/playwright-bdd/issues/46
|
|
22
|
+
let hasCustomTest = exports.hasCustomTest = false;
|
|
23
|
+
function createBdd(customTest, _CustomWorld) {
|
|
24
|
+
if (!hasCustomTest) {
|
|
25
|
+
exports.hasCustomTest = hasCustomTest = isCustomTest(customTest);
|
|
26
|
+
}
|
|
27
|
+
const Given = defineStepCtor('Given', hasCustomTest);
|
|
28
|
+
const When = defineStepCtor('When', hasCustomTest);
|
|
29
|
+
const Then = defineStepCtor('Then', hasCustomTest);
|
|
30
|
+
const Step = defineStepCtor('Unknown', hasCustomTest);
|
|
31
|
+
const Before = (0, _scenario.scenarioHookFactory)('before');
|
|
32
|
+
const After = (0, _scenario.scenarioHookFactory)('after');
|
|
33
|
+
const BeforeAll = (0, _worker.workerHookFactory)('beforeAll');
|
|
34
|
+
const AfterAll = (0, _worker.workerHookFactory)('afterAll');
|
|
35
|
+
return {
|
|
36
|
+
Given,
|
|
37
|
+
When,
|
|
38
|
+
Then,
|
|
39
|
+
Step,
|
|
40
|
+
Before,
|
|
41
|
+
After,
|
|
42
|
+
BeforeAll,
|
|
43
|
+
AfterAll
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function defineStepCtor(keyword, hasCustomTest) {
|
|
47
|
+
return (pattern, fn) => {
|
|
48
|
+
(0, _defineStep.defineStep)({
|
|
49
|
+
keyword,
|
|
50
|
+
pattern,
|
|
51
|
+
fn,
|
|
52
|
+
hasCustomTest
|
|
53
|
+
});
|
|
54
|
+
return (fixtures, ...args) => {
|
|
55
|
+
assertStepIsCalledWithRequiredFixtures(pattern, fn, fixtures);
|
|
56
|
+
return fn(fixtures, ...args);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function isCustomTest(customTest) {
|
|
61
|
+
if (!customTest || customTest === _bddFixtures.test) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
assertTestHasBddFixtures(customTest);
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
function assertTestHasBddFixtures(customTest) {
|
|
68
|
+
if (!(0, _testTypeImpl.isTestContainsSubtest)(customTest, _bddFixtures.test)) {
|
|
69
|
+
(0, _exit.exit)(`createBdd() should use 'test' extended from "playwright-bdd"`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function assertStepIsCalledWithRequiredFixtures(pattern, fn, fixtures) {
|
|
73
|
+
const fixtureNames = (0, _fixtureParameterNames.fixtureParameterNames)(fn);
|
|
74
|
+
const missingFixtures = fixtureNames.filter(fixtureName => !Object.prototype.hasOwnProperty.call(fixtures, fixtureName));
|
|
75
|
+
if (missingFixtures.length) {
|
|
76
|
+
throw new Error([`Invocation of step "${pattern}" from another step does not pass all required fixtures.`, `Missings fixtures: ${missingFixtures.join(', ')}`].join(' '));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Fixture = Fixture;
|
|
7
|
+
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
8
|
+
var _steps = require("./steps");
|
|
9
|
+
var _exit = require("../../utils/exit");
|
|
10
|
+
/**
|
|
11
|
+
* Class level @Fixture decorator.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Graph of POM class inheritance.
|
|
16
|
+
* Allows to guess correct fixture by step text.
|
|
17
|
+
*/
|
|
18
|
+
const pomGraph = new Map();
|
|
19
|
+
/**
|
|
20
|
+
* @Fixture decorator.
|
|
21
|
+
*/
|
|
22
|
+
function Fixture(fixtureName) {
|
|
23
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
24
|
+
return (Ctor, _context) => {
|
|
25
|
+
createPomNode(Ctor, fixtureName);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createPomNode(Ctor, fixtureName) {
|
|
29
|
+
const pomNode = {
|
|
30
|
+
fixtureName,
|
|
31
|
+
className: Ctor.name,
|
|
32
|
+
children: new Set()
|
|
33
|
+
};
|
|
34
|
+
ensureUniqueFixtureName(pomNode);
|
|
35
|
+
pomGraph.set(Ctor, pomNode);
|
|
36
|
+
(0, _steps.linkStepsWithPomNode)(Ctor, pomNode);
|
|
37
|
+
linkParentWithPomNode(Ctor, pomNode);
|
|
38
|
+
return pomNode;
|
|
39
|
+
}
|
|
40
|
+
function ensureUniqueFixtureName({
|
|
41
|
+
fixtureName,
|
|
42
|
+
className
|
|
43
|
+
}) {
|
|
44
|
+
if (!fixtureName) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const existingPom = getPomNodeByFixtureName(fixtureName);
|
|
48
|
+
if (existingPom) {
|
|
49
|
+
(0, _exit.exit)(`Duplicate fixture name "${fixtureName}"`, `defined for classes: ${existingPom.className}, ${className}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function linkParentWithPomNode(Ctor, pomNode) {
|
|
53
|
+
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
54
|
+
if (!parentCtor) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// if parentCtor is not in pomGraph, add it.
|
|
58
|
+
// Case: parent class is not marked with @Fixture, but has decorator steps (base class)
|
|
59
|
+
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
60
|
+
parentPomNode.children.add(pomNode);
|
|
61
|
+
}
|
|
62
|
+
function getPomNodeByFixtureName(fixtureName) {
|
|
63
|
+
for (const pomNode of pomGraph.values()) {
|
|
64
|
+
if (pomNode.fixtureName === fixtureName) {
|
|
65
|
+
return pomNode;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.appendDecoratorSteps = appendDecoratorSteps;
|
|
7
|
+
exports.createStepDecorator = createStepDecorator;
|
|
8
|
+
exports.linkStepsWithPomNode = linkStepsWithPomNode;
|
|
9
|
+
var _bddFixtures = require("../../run/bddFixtures");
|
|
10
|
+
var _buildStepDefinition = require("../../cucumber/buildStepDefinition");
|
|
11
|
+
var _defineStep = require("../defineStep");
|
|
12
|
+
/**
|
|
13
|
+
* Define steps via decorators.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
// initially we sotre step data inside method,
|
|
17
|
+
// and then extract it in @Fixture decorator call
|
|
18
|
+
const decoratedStepSymbol = Symbol('decoratedStep');
|
|
19
|
+
// global list of all decorator steps
|
|
20
|
+
const decoratedSteps = new Set();
|
|
21
|
+
/**
|
|
22
|
+
* Creates @Given, @When, @Then decorators.
|
|
23
|
+
*/
|
|
24
|
+
function createStepDecorator(keyword) {
|
|
25
|
+
return pattern => {
|
|
26
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
27
|
+
return (method, _context) => {
|
|
28
|
+
saveStepConfigToMethod(method, {
|
|
29
|
+
keyword,
|
|
30
|
+
pattern,
|
|
31
|
+
fn: method,
|
|
32
|
+
hasCustomTest: true
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function linkStepsWithPomNode(Ctor, pomNode) {
|
|
38
|
+
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
42
|
+
return Object.values(propertyDescriptors).forEach(descriptor => {
|
|
43
|
+
const stepConfig = getStepConfigFromMethod(descriptor);
|
|
44
|
+
if (!stepConfig) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
stepConfig.pomNode = pomNode;
|
|
48
|
+
decoratedSteps.add(stepConfig);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Append decorator steps to Cucumber's supportCodeLibrary.
|
|
53
|
+
*/
|
|
54
|
+
function appendDecoratorSteps(supportCodeLibrary) {
|
|
55
|
+
decoratedSteps.forEach(stepConfig => {
|
|
56
|
+
const {
|
|
57
|
+
keyword,
|
|
58
|
+
pattern,
|
|
59
|
+
fn
|
|
60
|
+
} = stepConfig;
|
|
61
|
+
stepConfig.fn = (fixturesArg, ...args) => {
|
|
62
|
+
const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
63
|
+
return fn.call(fixture, ...args);
|
|
64
|
+
};
|
|
65
|
+
const code = (0, _defineStep.buildCucumberStepCode)(stepConfig);
|
|
66
|
+
const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
67
|
+
keyword,
|
|
68
|
+
pattern,
|
|
69
|
+
code,
|
|
70
|
+
line: 0,
|
|
71
|
+
// not used in playwright-bdd
|
|
72
|
+
options: {},
|
|
73
|
+
// not used in playwright-bdd
|
|
74
|
+
uri: '' // not used in playwright-bdd
|
|
75
|
+
}, supportCodeLibrary);
|
|
76
|
+
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
77
|
+
});
|
|
78
|
+
decoratedSteps.clear();
|
|
79
|
+
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
80
|
+
}
|
|
81
|
+
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
82
|
+
// there should be exatcly one suitable fixture in fixturesArg
|
|
83
|
+
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
84
|
+
if (fixtureNames.length === 0) {
|
|
85
|
+
throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
86
|
+
}
|
|
87
|
+
if (fixtureNames.length > 1) {
|
|
88
|
+
throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
89
|
+
}
|
|
90
|
+
return fixturesArg[fixtureNames[0]];
|
|
91
|
+
}
|
|
92
|
+
function saveStepConfigToMethod(method, stepConfig) {
|
|
93
|
+
method[decoratedStepSymbol] = stepConfig;
|
|
94
|
+
}
|
|
95
|
+
function getStepConfigFromMethod(descriptor) {
|
|
96
|
+
// filter out getters / setters
|
|
97
|
+
return typeof descriptor.value === 'function' ? descriptor.value[decoratedStepSymbol] : undefined;
|
|
98
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildCucumberStepCode = buildCucumberStepCode;
|
|
7
|
+
exports.defineStep = defineStep;
|
|
8
|
+
exports.getStepCode = getStepCode;
|
|
9
|
+
var _cucumber = require("@cucumber/cucumber");
|
|
10
|
+
var _exit = require("../utils/exit");
|
|
11
|
+
/**
|
|
12
|
+
* Defines step by config.
|
|
13
|
+
* Calls cucumber's Given(), When(), Then() under the hood.
|
|
14
|
+
*/
|
|
15
|
+
function defineStep(stepConfig) {
|
|
16
|
+
const {
|
|
17
|
+
keyword,
|
|
18
|
+
pattern
|
|
19
|
+
} = stepConfig;
|
|
20
|
+
const cucumberDefineStepFn = getCucumberDefineStepFn(keyword);
|
|
21
|
+
const code = buildCucumberStepCode(stepConfig);
|
|
22
|
+
try {
|
|
23
|
+
cucumberDefineStepFn(pattern, code);
|
|
24
|
+
} catch (e) {
|
|
25
|
+
// todo: detect that this is import from test file
|
|
26
|
+
// and skip/delay registering cucumber steps until cucumber is loaded
|
|
27
|
+
const isMissingCucumber = /Cucumber that isn't running/i.test(e.message);
|
|
28
|
+
if (isMissingCucumber) {
|
|
29
|
+
(0, _exit.exit)(`Option "importTestFrom" should point to a separate file without step definitions`, `(e.g. without calls of Given, When, Then)`);
|
|
30
|
+
} else {
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function buildCucumberStepCode(stepConfig) {
|
|
36
|
+
const code = function (...args) {
|
|
37
|
+
// build the first argument (fixtures) for step fn
|
|
38
|
+
const fixturesArg = Object.assign({}, this.$internal.currentStepFixtures, {
|
|
39
|
+
$testInfo: this.testInfo,
|
|
40
|
+
$test: this.test,
|
|
41
|
+
$tags: this.tags
|
|
42
|
+
});
|
|
43
|
+
return stepConfig.fn.call(this, fixturesArg, ...args);
|
|
44
|
+
};
|
|
45
|
+
code.stepConfig = stepConfig;
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
48
|
+
function getStepCode(stepDefinition) {
|
|
49
|
+
return stepDefinition.code;
|
|
50
|
+
}
|
|
51
|
+
function getCucumberDefineStepFn(keyword) {
|
|
52
|
+
switch (keyword) {
|
|
53
|
+
case 'Given':
|
|
54
|
+
return _cucumber.Given;
|
|
55
|
+
case 'When':
|
|
56
|
+
return _cucumber.When;
|
|
57
|
+
case 'Then':
|
|
58
|
+
return _cucumber.Then;
|
|
59
|
+
default:
|
|
60
|
+
return _cucumber.defineStep;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getStepConfig = getStepConfig;
|
|
7
|
+
exports.isDecorator = isDecorator;
|
|
8
|
+
exports.isPlaywrightStyle = isPlaywrightStyle;
|
|
9
|
+
/**
|
|
10
|
+
* Playwright-bdd's step config.
|
|
11
|
+
*/
|
|
12
|
+
function getStepConfig(step) {
|
|
13
|
+
return step.code.stepConfig;
|
|
14
|
+
}
|
|
15
|
+
function isDecorator(stepConfig) {
|
|
16
|
+
return Boolean(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.pomNode);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Cucumber-style steps don't have stepConfig
|
|
20
|
+
* b/c they created directly via cucumber's Given, When, Then.
|
|
21
|
+
*/
|
|
22
|
+
function isPlaywrightStyle(stepConfig) {
|
|
23
|
+
return Boolean(stepConfig);
|
|
24
|
+
}
|
|
@@ -8,17 +8,32 @@ exports.initializeEnvConfig = initializeEnvConfig;
|
|
|
8
8
|
var _fs = require("fs");
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _configFileNameProvider = require("./helpers/configFileNameProvider");
|
|
11
|
+
var _logger = require("../../utils/logger");
|
|
12
|
+
var _getUsers = require("./helpers/auth/getUsers");
|
|
11
13
|
function setEnvironmentVariables(mode, configJSON) {
|
|
12
14
|
process.env.mode = mode;
|
|
13
15
|
for (const key in configJSON) {
|
|
14
16
|
process.env[key] = configJSON[key];
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
|
-
function
|
|
19
|
+
function addHelperLogsForEnvInitialization() {
|
|
20
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Mode under which test cases should run has not been specified in args.`);
|
|
21
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Please specify --mode='dev/prod' while running ZDTestingFramework test`);
|
|
22
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Going to use default mode as dev`);
|
|
23
|
+
}
|
|
24
|
+
function initializeEnvConfig(mode) {
|
|
18
25
|
try {
|
|
26
|
+
if (!mode) {
|
|
27
|
+
addHelperLogsForEnvInitialization();
|
|
28
|
+
mode = 'dev';
|
|
29
|
+
}
|
|
19
30
|
const configFile = (0, _fs.readFileSync)(_path.default.resolve(process.cwd(), `./${(0, _configFileNameProvider.getEnvConfigFilePath)(mode)}`));
|
|
20
31
|
const configJSON = JSON.parse(configFile);
|
|
21
|
-
|
|
32
|
+
const defaultActorConfiguration = (0, _getUsers.getDefaultActor)();
|
|
33
|
+
setEnvironmentVariables(mode, {
|
|
34
|
+
...configJSON,
|
|
35
|
+
...defaultActorConfiguration
|
|
36
|
+
});
|
|
22
37
|
} catch (err) {
|
|
23
38
|
throw new Error(`Config File Not Exists. Please provide a config file ${(0, _configFileNameProvider.getEnvConfigFilePath)(mode)} to intiailize the environment variables`);
|
|
24
39
|
}
|
|
@@ -14,6 +14,7 @@ function getUATFileName() {
|
|
|
14
14
|
}
|
|
15
15
|
function getEnvConfigFilePath(mode) {
|
|
16
16
|
const confFilePath = _path.default.resolve(process.cwd(), `uat/conf/${mode}/settings.json`);
|
|
17
|
+
// TODO: Actors Mode as config
|
|
17
18
|
if (_fs.default.existsSync(confFilePath)) {
|
|
18
19
|
return `uat/conf/${mode}/settings.json`;
|
|
19
20
|
}
|
|
@@ -4,13 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.When = exports.Then = exports.Given = void 0;
|
|
8
|
-
Object.defineProperty(exports, "accountLogin", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return _index.accountLogin;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
7
|
Object.defineProperty(exports, "createBdd", {
|
|
15
8
|
enumerable: true,
|
|
16
9
|
get: function () {
|
|
@@ -23,67 +16,25 @@ Object.defineProperty(exports, "expect", {
|
|
|
23
16
|
return _test.expect;
|
|
24
17
|
}
|
|
25
18
|
});
|
|
26
|
-
Object.defineProperty(exports, "getDefaultActor", {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return _index.getDefaultActor;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports, "getListOfActors", {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _index.getListOfActors;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(exports, "getRunMode", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _index.getRunMode;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, "getUserForSelectedEditionAndProfile", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return _index.getUserForSelectedEditionAndProfile;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(exports, "isCI", {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function () {
|
|
53
|
-
return _index.isCI;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, "isDevelopmentSetup", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () {
|
|
59
|
-
return _index.isDevelopmentSetup;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(exports, "loadCookiesIfPresent", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return _index.loadCookiesIfPresent;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(exports, "performLoginSteps", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function () {
|
|
71
|
-
return _index.performLoginSteps;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
19
|
exports.test = void 0;
|
|
75
|
-
Object.defineProperty(exports, "verifyIfCookieFileExists", {
|
|
76
|
-
enumerable: true,
|
|
77
|
-
get: function () {
|
|
78
|
-
return _index.verifyIfCookieFileExists;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
20
|
var _bddFramework = require("../../bdd-framework");
|
|
82
21
|
var _test = require("@playwright/test");
|
|
83
22
|
var _readConfigFile = require("./readConfigFile");
|
|
84
23
|
var _builtInFixtures = _interopRequireDefault(require("./builtInFixtures"));
|
|
85
|
-
var _index = require("./helpers/auth/index");
|
|
86
24
|
var _getUserFixtures = _interopRequireDefault(require("./helpers/getUserFixtures"));
|
|
25
|
+
// import {
|
|
26
|
+
// accountLogin,
|
|
27
|
+
// getRunMode,
|
|
28
|
+
// isCI,
|
|
29
|
+
// isDevelopmentSetup,
|
|
30
|
+
// getListOfActors,
|
|
31
|
+
// getDefaultActor,
|
|
32
|
+
// getUserForSelectedEditionAndProfile,
|
|
33
|
+
// loadCookiesIfPresent,
|
|
34
|
+
// performLoginSteps,
|
|
35
|
+
// verifyIfCookieFileExists
|
|
36
|
+
// } from './helpers/auth/index';
|
|
37
|
+
|
|
87
38
|
const {
|
|
88
39
|
bddMode
|
|
89
40
|
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
@@ -93,12 +44,4 @@ const userFixtures = (0, _getUserFixtures.default)();
|
|
|
93
44
|
const test = exports.test = base.extend({
|
|
94
45
|
...buildInFixtures,
|
|
95
46
|
...userFixtures
|
|
96
|
-
});
|
|
97
|
-
const {
|
|
98
|
-
Given,
|
|
99
|
-
When,
|
|
100
|
-
Then
|
|
101
|
-
} = (0, _bddFramework.createBdd)();
|
|
102
|
-
exports.Then = Then;
|
|
103
|
-
exports.When = When;
|
|
104
|
-
exports.Given = Given;
|
|
47
|
+
});
|
|
@@ -12,6 +12,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
12
12
|
var _logger = require("../../utils/logger");
|
|
13
13
|
var _configFileNameProvider = require("./helpers/configFileNameProvider");
|
|
14
14
|
var _mergeObjects = require("./helpers/mergeObjects");
|
|
15
|
+
let cachedConfig = null;
|
|
15
16
|
function getDefaultConfig() {
|
|
16
17
|
return {
|
|
17
18
|
uatDirectory: _path.default.join(process.cwd(), 'uat'),
|
|
@@ -31,7 +32,7 @@ function getDefaultConfig() {
|
|
|
31
32
|
height: 720
|
|
32
33
|
},
|
|
33
34
|
debug: false,
|
|
34
|
-
mode: 'dev',
|
|
35
|
+
mode: process.env.mode || 'dev',
|
|
35
36
|
additionalPages: {},
|
|
36
37
|
featureFilesFolder: 'feature-files',
|
|
37
38
|
stepDefinitionsFolder: 'steps',
|
|
@@ -40,10 +41,17 @@ function getDefaultConfig() {
|
|
|
40
41
|
editionOrder: ['Free', 'Express', 'Standard', 'Professional', 'Enterprise']
|
|
41
42
|
};
|
|
42
43
|
}
|
|
44
|
+
function checkForDeprecatedKeys(configKey) {
|
|
45
|
+
let deprecatedConfigInUatConfigFile = ['mode'];
|
|
46
|
+
if (deprecatedConfigInUatConfigFile.includes(configKey)) {
|
|
47
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `key ${configKey} is deprecated. Please use other options`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
43
50
|
function combineDefaultConfigWithUserConfig(userConfiguration) {
|
|
44
51
|
let defaultConfig = getDefaultConfig();
|
|
45
52
|
let configurationObj = {};
|
|
46
53
|
Object.keys(userConfiguration).forEach(configKey => {
|
|
54
|
+
checkForDeprecatedKeys(configKey);
|
|
47
55
|
let configValue = userConfiguration[configKey];
|
|
48
56
|
if (configValue !== null && configValue !== undefined) {
|
|
49
57
|
configurationObj[configKey] = configValue;
|
|
@@ -80,7 +88,6 @@ function combineDefaultConfigWithUserConfig(userConfiguration) {
|
|
|
80
88
|
* @property {number} trace - trace for test cases.
|
|
81
89
|
* @property {boolean} video - video for test cases,
|
|
82
90
|
* @property {boolean} debug - debug mode
|
|
83
|
-
* @property {string} mode: mode in which the test cases needs to run
|
|
84
91
|
* @property {boolean} isAuthMode - Auth Mode. config whether authentication step needed before running test cases
|
|
85
92
|
* @property {string} authFilePath - File Path where the cookies stored
|
|
86
93
|
* @property {any} browsers: List of browsers
|
|
@@ -104,11 +111,15 @@ function combineDefaultConfigWithUserConfig(userConfiguration) {
|
|
|
104
111
|
* @returns {UserConfig}
|
|
105
112
|
*/
|
|
106
113
|
function generateConfigFromFile() {
|
|
114
|
+
if (cachedConfig !== null) {
|
|
115
|
+
return cachedConfig; // If cached, return the cached configuration
|
|
116
|
+
}
|
|
107
117
|
const filePath = _path.default.resolve(process.cwd(), (0, _configFileNameProvider.getUATFileName)());
|
|
108
118
|
if ((0, _fs.existsSync)(filePath)) {
|
|
109
119
|
/** @type {UserConfig} */
|
|
110
120
|
const config = require(filePath);
|
|
111
121
|
const modifiedConfiguration = combineDefaultConfigWithUserConfig(config);
|
|
122
|
+
cachedConfig = modifiedConfiguration;
|
|
112
123
|
return modifiedConfiguration;
|
|
113
124
|
}
|
|
114
125
|
return {};
|