@zohodesk/testinglibrary 0.1.9 → 0.2.1
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/builtInFixtures/page.js +21 -14
- package/build/core/playwright/clear-caches.js +5 -3
- package/build/core/playwright/env-initializer.js +22 -6
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +10 -5
- package/build/core/playwright/helpers/auth/getUsers.js +79 -32
- package/build/core/playwright/helpers/auth/index.js +22 -4
- package/build/core/playwright/helpers/auth/loginSteps.js +2 -2
- package/build/core/playwright/helpers/configFileNameProvider.js +9 -1
- package/build/core/playwright/index.js +14 -59
- package/build/core/playwright/readConfigFile.js +14 -2
- package/build/core/playwright/test-runner.js +2 -3
- package/build/index.d.ts +17 -18
- package/build/index.js +16 -4
- package/build/setup-folder-structure/samples/auth-setup-sample.js +22 -21
- package/build/setup-folder-structure/setupProject.js +1 -0
- package/build/utils/fileUtils.js +5 -0
- package/changelog.md +18 -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
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
|
-
var
|
|
9
|
-
var _loginSteps = _interopRequireDefault(require("../helpers/auth/loginSteps"));
|
|
7
|
+
var _auth = require("../helpers/auth");
|
|
10
8
|
var _readConfigFile = require("../readConfigFile");
|
|
11
9
|
/* eslint-disable global-require */
|
|
12
10
|
|
|
@@ -19,12 +17,14 @@ function getTagInputFromSelectedTags(tags, inputString) {
|
|
|
19
17
|
return tagInput;
|
|
20
18
|
}
|
|
21
19
|
function getCustomAccountDetails(tags) {
|
|
22
|
-
const
|
|
20
|
+
const tagsTobeFiltered = ['@profile', '@edition', '@beta', '@portal'];
|
|
21
|
+
const filteredTags = tags.filter(tag => tagsTobeFiltered.some(prefix => tag.startsWith(prefix)));
|
|
23
22
|
if (filteredTags && filteredTags.length > 0) {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
23
|
+
const portalInfo = getTagInputFromSelectedTags(filteredTags, '@portal');
|
|
24
|
+
const betaFeature = getTagInputFromSelectedTags(filteredTags, '@beta');
|
|
25
|
+
const profileInfo = getTagInputFromSelectedTags(filteredTags, '@profile');
|
|
26
|
+
const editionInfo = getTagInputFromSelectedTags(filteredTags, '@edition');
|
|
27
|
+
const user = (0, _auth.getUserForSelectedEditionAndProfile)(editionInfo, profileInfo, betaFeature, portalInfo);
|
|
28
28
|
return user;
|
|
29
29
|
}
|
|
30
30
|
return null;
|
|
@@ -53,22 +53,29 @@ var _default = exports.default = {
|
|
|
53
53
|
$tags,
|
|
54
54
|
page
|
|
55
55
|
}, use) => {
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
56
|
+
const testPortalDetails = getCustomAccountDetails($tags);
|
|
57
|
+
if (testPortalDetails === null) {
|
|
58
58
|
await performDefaultPageSteps({
|
|
59
59
|
context,
|
|
60
60
|
$tags,
|
|
61
61
|
page
|
|
62
62
|
});
|
|
63
|
+
const user = (0, _auth.getDefaultActor)();
|
|
64
|
+
process.env.actorInfo = JSON.stringify(user);
|
|
63
65
|
await use(page);
|
|
64
66
|
} else {
|
|
65
67
|
await context.clearCookies();
|
|
66
|
-
|
|
68
|
+
const {
|
|
69
|
+
email,
|
|
70
|
+
password
|
|
71
|
+
} = testPortalDetails;
|
|
72
|
+
await (0, _auth.performLoginSteps)({
|
|
67
73
|
page,
|
|
68
|
-
|
|
69
|
-
useremail:
|
|
70
|
-
password:
|
|
74
|
+
authFilePrefix: email,
|
|
75
|
+
useremail: email,
|
|
76
|
+
password: password
|
|
71
77
|
}, async () => page.url().includes(process.env.domain));
|
|
78
|
+
process.env.actorInfo = JSON.stringify(testPortalDetails);
|
|
72
79
|
await performDefaultPageSteps({
|
|
73
80
|
context,
|
|
74
81
|
$tags,
|
|
@@ -10,9 +10,10 @@ var _fileUtils = require("../../utils/fileUtils");
|
|
|
10
10
|
var _logger = require("../../utils/logger");
|
|
11
11
|
var _readConfigFile = require("./readConfigFile");
|
|
12
12
|
function deleteAuthFiles(authFilePath) {
|
|
13
|
-
authFilePath.
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
authFilePath = _path.default.resolve(process.cwd(), authFilePath);
|
|
14
|
+
const authFileFolder = _path.default.dirname(authFilePath);
|
|
15
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting auth files present in ${authFileFolder}`);
|
|
16
|
+
(0, _fileUtils.deleteFolder)(authFileFolder);
|
|
16
17
|
}
|
|
17
18
|
function deletePlaywrightReport(reportPath) {
|
|
18
19
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting Playwright report ${reportPath}`);
|
|
@@ -34,6 +35,7 @@ function clearCaches() {
|
|
|
34
35
|
deleteGeneratedFeatures();
|
|
35
36
|
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Caches Cleared. Now you can try running npm run uat');
|
|
36
37
|
} catch (err) {
|
|
38
|
+
_logger.Logger.error(err);
|
|
37
39
|
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Error While clearing cookies. Try manually delete folder uat/playwright and uat/playwright-report');
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -8,18 +8,34 @@ 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
|
-
for (const key in configJSON
|
|
14
|
-
process.env[key] = configJSON[
|
|
15
|
+
for (const key in configJSON) {
|
|
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 {
|
|
19
|
-
|
|
26
|
+
if (!mode) {
|
|
27
|
+
addHelperLogsForEnvInitialization();
|
|
28
|
+
mode = 'dev';
|
|
29
|
+
}
|
|
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.getDefaultActorConf)();
|
|
33
|
+
setEnvironmentVariables(mode, {
|
|
34
|
+
...configJSON,
|
|
35
|
+
...defaultActorConfiguration
|
|
36
|
+
});
|
|
22
37
|
} catch (err) {
|
|
23
|
-
|
|
38
|
+
_logger.Logger.error(err);
|
|
39
|
+
throw new Error(`Config File Not Exists. Please provide a config file ${(0, _configFileNameProvider.getEnvConfigFilePath)(mode)} to intiailize the environment variables `);
|
|
24
40
|
}
|
|
25
41
|
}
|
|
@@ -4,22 +4,26 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.getAuthFileDirectory = getAuthFileDirectory;
|
|
8
8
|
exports.loadCookiesIfPresent = loadCookiesIfPresent;
|
|
9
9
|
exports.verifyIfCookieFileExists = verifyIfCookieFileExists;
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
var _fs = require("fs");
|
|
12
12
|
var _readConfigFile = require("../../readConfigFile");
|
|
13
|
+
var _logger = require("../../../../utils/logger");
|
|
13
14
|
/* eslint-disable no-console */
|
|
14
15
|
|
|
15
|
-
const {
|
|
16
|
-
uatDirectory
|
|
17
|
-
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
18
|
-
const authDirectory = exports.authDirectory = _path.default.resolve(_path.default.join(uatDirectory, 'playwright', '.auth'));
|
|
19
16
|
const authContent = {
|
|
20
17
|
cookies: []
|
|
21
18
|
};
|
|
19
|
+
function getAuthFileDirectory() {
|
|
20
|
+
const {
|
|
21
|
+
uatDirectory
|
|
22
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
23
|
+
return _path.default.resolve(_path.default.join(uatDirectory, 'playwright', '.auth'));
|
|
24
|
+
}
|
|
22
25
|
function verifyIfCookieFileExists(authFile) {
|
|
26
|
+
const authDirectory = getAuthFileDirectory();
|
|
23
27
|
if (!(0, _fs.existsSync)(authDirectory)) {
|
|
24
28
|
console.log('Creating auth directory for the first time setup...');
|
|
25
29
|
(0, _fs.mkdirSync)(authDirectory, {
|
|
@@ -35,6 +39,7 @@ function convertCookiesToParse(cookies, authFilePath) {
|
|
|
35
39
|
try {
|
|
36
40
|
return JSON.parse(cookies);
|
|
37
41
|
} catch (err) {
|
|
42
|
+
_logger.Logger.error(err);
|
|
38
43
|
throw new Error(` Error while parsing cookies ${err} \n${_path.default.resolve(process.cwd(), authFilePath)} File is Empty`);
|
|
39
44
|
// process.exit()
|
|
40
45
|
}
|