@zohodesk/testinglibrary 0.0.4 → 0.0.5-exp.10
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/.babelrc +16 -0
- package/bin/cli.js +1 -1
- package/bin/postinstall.js +1 -16
- package/build/bdd-framework/cli/commands/env.js +44 -0
- package/build/bdd-framework/cli/commands/export.js +47 -0
- package/build/bdd-framework/cli/commands/test.js +60 -0
- package/build/bdd-framework/cli/index.js +11 -0
- package/build/bdd-framework/cli/options.js +21 -0
- package/build/bdd-framework/cli/worker.js +13 -0
- package/build/bdd-framework/config/dir.js +27 -0
- package/build/bdd-framework/config/env.js +49 -0
- package/build/bdd-framework/config/index.js +92 -0
- package/build/bdd-framework/cucumber/buildStepDefinition.js +45 -0
- package/build/bdd-framework/cucumber/gherkin.d.ts +45 -0
- package/build/bdd-framework/cucumber/loadConfig.js +17 -0
- package/build/bdd-framework/cucumber/loadFeatures.js +39 -0
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +20 -0
- package/build/bdd-framework/cucumber/loadSources.js +58 -0
- package/build/bdd-framework/cucumber/loadSteps.js +41 -0
- package/build/bdd-framework/decorators.js +21 -0
- package/build/bdd-framework/gen/formatter.js +92 -0
- package/build/bdd-framework/gen/i18n.js +44 -0
- package/build/bdd-framework/gen/index.js +150 -0
- package/build/bdd-framework/gen/poms.js +47 -0
- package/build/bdd-framework/gen/testFile.js +356 -0
- package/build/bdd-framework/gen/testNode.js +50 -0
- package/build/bdd-framework/index.js +33 -0
- package/build/bdd-framework/playwright/fixtureParameterNames.js +103 -0
- package/build/bdd-framework/playwright/getLocationInFile.js +50 -0
- package/build/bdd-framework/playwright/loadConfig.js +42 -0
- package/build/bdd-framework/playwright/testTypeImpl.js +47 -0
- package/build/bdd-framework/playwright/transform.js +85 -0
- package/build/bdd-framework/playwright/utils.js +24 -0
- package/build/bdd-framework/run/bddFixtures.js +109 -0
- package/build/bdd-framework/run/bddWorld.js +91 -0
- package/build/bdd-framework/snippets/index.js +132 -0
- package/build/bdd-framework/snippets/snippetSyntax.js +50 -0
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +32 -0
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +18 -0
- package/build/bdd-framework/stepDefinitions/createBdd.js +52 -0
- package/build/bdd-framework/stepDefinitions/createDecorators.js +110 -0
- package/build/bdd-framework/stepDefinitions/defineStep.js +62 -0
- package/build/bdd-framework/utils/index.js +52 -0
- package/build/bdd-framework/utils/jsStringWrap.js +44 -0
- package/build/bdd-framework/utils/logger.js +21 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +13 -0
- package/{src → build}/core/jest/runner/jest-runner.js +16 -15
- package/build/core/jest/setup/index.js +9 -0
- package/build/core/playwright/codegen.js +56 -0
- package/build/core/playwright/custom-commands.js +8 -0
- package/build/core/playwright/env-initializer.js +21 -0
- package/{src → build}/core/playwright/index.js +51 -21
- package/build/core/playwright/readConfigFile.js +64 -0
- package/build/core/playwright/report-generator.js +43 -0
- package/build/core/playwright/setup/config-creator.js +106 -0
- package/build/core/playwright/test-runner.js +106 -0
- package/build/index.js +37 -0
- package/build/lib/cli.js +45 -0
- package/build/lib/post-install.js +17 -0
- package/build/lint/index.js +7 -0
- package/build/setup-folder-structure/env-config-sample.json +17 -0
- package/build/setup-folder-structure/git-ignore.sample.js +39 -0
- package/build/setup-folder-structure/setupProject.js +104 -0
- package/build/setup-folder-structure/uat-config-sample.js +31 -0
- package/build/setup-folder-structure/user-example.json +3 -0
- package/build/utils/cliArgsToObject.js +64 -0
- package/build/utils/getFilePath.js +11 -0
- package/build/utils/logger.js +56 -0
- package/build/utils/rootPath.js +46 -0
- package/changelog.md +27 -0
- package/npm-shrinkwrap.json +2097 -147
- package/package.json +20 -5
- package/playwright.config.js +6 -6
- package/src/core/jest/preprocessor/jsPreprocessor.js +0 -9
- package/src/core/jest/setup/index.js +0 -165
- package/src/core/playwright/codegen.js +0 -60
- package/src/core/playwright/custom-commands.js +0 -3
- package/src/core/playwright/env-initializer.js +0 -24
- package/src/core/playwright/readConfigFile.js +0 -30
- package/src/core/playwright/report-generator.js +0 -43
- package/src/core/playwright/setup/config-creator.js +0 -77
- package/src/core/playwright/test-runner.js +0 -64
- package/src/index.js +0 -9
- package/src/lib/cli.js +0 -35
- package/src/utils/cliArgsToObject.js +0 -35
- package/src/utils/getFilePath.js +0 -9
- package/src/utils/logger.js +0 -28
- package/src/utils/rootPath.js +0 -51
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Fixture = Fixture;
|
|
7
|
+
exports.appendDecoratorSteps = appendDecoratorSteps;
|
|
8
|
+
exports.createStepDecorator = createStepDecorator;
|
|
9
|
+
exports.getPomNodeByFixtureName = getPomNodeByFixtureName;
|
|
10
|
+
var _bddFixtures = require("../run/bddFixtures");
|
|
11
|
+
var _defineStep = require("./defineStep");
|
|
12
|
+
var _buildStepDefinition = require("../cucumber/buildStepDefinition");
|
|
13
|
+
/**
|
|
14
|
+
* Define steps via decorators.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
18
|
+
|
|
19
|
+
const pomGraph = new Map();
|
|
20
|
+
const decoratedStepSymbol = Symbol('decoratedStep');
|
|
21
|
+
const decoratedSteps = new Set();
|
|
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 createStepDecorator(keyword) {
|
|
29
|
+
return pattern => {
|
|
30
|
+
// context parameter is required for decorator by TS even though it's not used
|
|
31
|
+
return (method, _context) => {
|
|
32
|
+
method[decoratedStepSymbol] = {
|
|
33
|
+
keyword,
|
|
34
|
+
pattern,
|
|
35
|
+
fn: method,
|
|
36
|
+
hasCustomTest: true,
|
|
37
|
+
isDecorator: true
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function appendDecoratorSteps(supportCodeLibrary) {
|
|
43
|
+
decoratedSteps.forEach(stepConfig => {
|
|
44
|
+
const {
|
|
45
|
+
keyword,
|
|
46
|
+
pattern,
|
|
47
|
+
fn
|
|
48
|
+
} = stepConfig;
|
|
49
|
+
stepConfig.fn = (fixturesArg, ...args) => {
|
|
50
|
+
const fixture = getFirstNonAutoInjectFixture(fixturesArg, stepConfig);
|
|
51
|
+
return fn.call(fixture, ...args);
|
|
52
|
+
};
|
|
53
|
+
const code = (0, _defineStep.buildCucumberStepFn)(stepConfig);
|
|
54
|
+
const stepDefinition = (0, _buildStepDefinition.buildStepDefinition)({
|
|
55
|
+
keyword,
|
|
56
|
+
pattern,
|
|
57
|
+
code,
|
|
58
|
+
line: 0,
|
|
59
|
+
// not used in playwright-bdd
|
|
60
|
+
options: {},
|
|
61
|
+
// not used in playwright-bdd
|
|
62
|
+
uri: '' // not used in playwright-bdd
|
|
63
|
+
}, supportCodeLibrary);
|
|
64
|
+
supportCodeLibrary.stepDefinitions.push(stepDefinition);
|
|
65
|
+
});
|
|
66
|
+
decoratedSteps.clear();
|
|
67
|
+
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getPomNodeByFixtureName(fixtureName) {
|
|
71
|
+
for (const pomNode of pomGraph.values()) {
|
|
72
|
+
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function createPomNode(Ctor, fixtureName) {
|
|
76
|
+
const pomNode = {
|
|
77
|
+
fixtureName,
|
|
78
|
+
children: new Set()
|
|
79
|
+
};
|
|
80
|
+
pomGraph.set(Ctor, pomNode);
|
|
81
|
+
getDecoratedSteps(Ctor).forEach(stepConfig => {
|
|
82
|
+
stepConfig.pomNode = pomNode;
|
|
83
|
+
decoratedSteps.add(stepConfig);
|
|
84
|
+
});
|
|
85
|
+
const parentCtor = Object.getPrototypeOf(Ctor);
|
|
86
|
+
if (!parentCtor) return;
|
|
87
|
+
const parentPomNode = pomGraph.get(parentCtor) || createPomNode(parentCtor, '');
|
|
88
|
+
parentPomNode === null || parentPomNode === void 0 || parentPomNode.children.add(pomNode);
|
|
89
|
+
return pomNode;
|
|
90
|
+
}
|
|
91
|
+
function getDecoratedSteps(Ctor) {
|
|
92
|
+
if (!(Ctor !== null && Ctor !== void 0 && Ctor.prototype)) return [];
|
|
93
|
+
const propertyDescriptors = Object.getOwnPropertyDescriptors(Ctor.prototype);
|
|
94
|
+
return Object.keys(propertyDescriptors)
|
|
95
|
+
// filter out getters / setters
|
|
96
|
+
.filter(methodName => typeof propertyDescriptors[methodName].value === 'function').map(methodName => {
|
|
97
|
+
return propertyDescriptors[methodName].value[decoratedStepSymbol];
|
|
98
|
+
}).filter(Boolean);
|
|
99
|
+
}
|
|
100
|
+
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
101
|
+
// there should be exatcly one suitable fixture in fixturesArg
|
|
102
|
+
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
103
|
+
if (fixtureNames.length === 0) {
|
|
104
|
+
throw new Error(`No suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
105
|
+
}
|
|
106
|
+
if (fixtureNames.length > 1) {
|
|
107
|
+
throw new Error(`Several suitable fixtures found for decorator step "${stepConfig.pattern}"`);
|
|
108
|
+
}
|
|
109
|
+
return fixturesArg[fixtureNames[0]];
|
|
110
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildCucumberStepFn = buildCucumberStepFn;
|
|
7
|
+
exports.defineStep = defineStep;
|
|
8
|
+
exports.getStepConfig = getStepConfig;
|
|
9
|
+
exports.isPlaywrightStyle = isPlaywrightStyle;
|
|
10
|
+
var _cucumber = require("@cucumber/cucumber");
|
|
11
|
+
var _utils = require("../utils");
|
|
12
|
+
function defineStep(stepConfig) {
|
|
13
|
+
const {
|
|
14
|
+
keyword,
|
|
15
|
+
pattern
|
|
16
|
+
} = stepConfig;
|
|
17
|
+
const cucumberDefineStepFn = getCucumberDefineStepFn(keyword);
|
|
18
|
+
const code = buildCucumberStepFn(stepConfig);
|
|
19
|
+
try {
|
|
20
|
+
cucumberDefineStepFn(pattern, code);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
// todo: detect that this is import from test file
|
|
23
|
+
// and skip/delay registering cucumber steps until cucumber is loaded
|
|
24
|
+
const isMissingCucumber = /Cucumber that isn't running/i.test(e.message);
|
|
25
|
+
if (isMissingCucumber) {
|
|
26
|
+
(0, _utils.exitWithMessage)(`Option "importTestFrom" should point to separate file without step definitions`, `(e.g. without calls of Given, When, Then)`);
|
|
27
|
+
} else {
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function buildCucumberStepFn(stepConfig) {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
const code = function (...args) {
|
|
35
|
+
const fixturesArg = Object.assign({}, this.customFixtures, {
|
|
36
|
+
$testInfo: this.testInfo,
|
|
37
|
+
$test: this.test,
|
|
38
|
+
$tags: this.tags
|
|
39
|
+
});
|
|
40
|
+
return stepConfig.fn.call(this, fixturesArg, ...args);
|
|
41
|
+
};
|
|
42
|
+
code.stepConfig = stepConfig;
|
|
43
|
+
return code;
|
|
44
|
+
}
|
|
45
|
+
function getStepConfig(step) {
|
|
46
|
+
return step.code.stepConfig;
|
|
47
|
+
}
|
|
48
|
+
function isPlaywrightStyle(step) {
|
|
49
|
+
return Boolean(getStepConfig(step));
|
|
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,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.exitWithMessage = exitWithMessage;
|
|
8
|
+
exports.getPackageVersion = getPackageVersion;
|
|
9
|
+
exports.getSymbolByName = getSymbolByName;
|
|
10
|
+
exports.removeDuplicates = removeDuplicates;
|
|
11
|
+
exports.resolvePackageRoot = resolvePackageRoot;
|
|
12
|
+
exports.template = template;
|
|
13
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
|
+
var _path = _interopRequireDefault(require("path"));
|
|
15
|
+
var _logger = require("./logger");
|
|
16
|
+
function exitWithMessage(...messages) {
|
|
17
|
+
_logger.logger.error('ERROR:', ...messages);
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// See: https://stackoverflow.com/questions/50453640/how-can-i-get-the-value-of-a-symbol-property
|
|
22
|
+
function getSymbolByName(target, name) {
|
|
23
|
+
const ownKeys = Reflect.ownKeys(target);
|
|
24
|
+
const symbol = ownKeys.find(key => key.toString() === `Symbol(${name})`);
|
|
25
|
+
if (!symbol) {
|
|
26
|
+
throw new Error(`Symbol "${name}" not found in target. ownKeys: ${ownKeys}`);
|
|
27
|
+
}
|
|
28
|
+
return symbol;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Inserts params into template.
|
|
33
|
+
* Params defined as <param>.
|
|
34
|
+
*/
|
|
35
|
+
function template(t, params = {}) {
|
|
36
|
+
return t.replace(/<(.+?)>/g, (match, key) => {
|
|
37
|
+
return params[key] !== undefined ? String(params[key]) : match;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function removeDuplicates(arr) {
|
|
41
|
+
return [...new Set(arr)];
|
|
42
|
+
}
|
|
43
|
+
function resolvePackageRoot(packageName) {
|
|
44
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`);
|
|
45
|
+
return _path.default.dirname(packageJsonPath);
|
|
46
|
+
}
|
|
47
|
+
function getPackageVersion(packageName) {
|
|
48
|
+
const packageRoot = resolvePackageRoot(packageName);
|
|
49
|
+
const packageJsonPath = _path.default.join(packageRoot, 'package.json');
|
|
50
|
+
const packageJson = JSON.parse(_fs.default.readFileSync(packageJsonPath, 'utf8'));
|
|
51
|
+
return packageJson.version || '';
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.jsStringWrap = jsStringWrap;
|
|
7
|
+
/**
|
|
8
|
+
* Adopted version of https://github.com/joliss/js-string-escape
|
|
9
|
+
* - added support of backticks
|
|
10
|
+
* - added 'quotes' option to indicate which quotes to escape
|
|
11
|
+
* - wrap result string with provided quotes
|
|
12
|
+
*
|
|
13
|
+
* Considered alternative is https://github.com/mathiasbynens/jsesc,
|
|
14
|
+
* but it provides additional functionality and much slower
|
|
15
|
+
* See: https://github.com/mathiasbynens/jsesc/issues/16
|
|
16
|
+
*/
|
|
17
|
+
function jsStringWrap(str, {
|
|
18
|
+
quotes = 'single'
|
|
19
|
+
} = {}) {
|
|
20
|
+
const wrapQuote = quotes === 'single' ? "'" : quotes === 'double' ? '"' : '`';
|
|
21
|
+
// eslint-disable-next-line complexity
|
|
22
|
+
const escapedStr = ('' + str).replace(/["'`\\\n\r\u2028\u2029]/g, character => {
|
|
23
|
+
// Escape all characters not included in SingleStringCharacters and
|
|
24
|
+
// DoubleStringCharacters on
|
|
25
|
+
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
26
|
+
switch (character) {
|
|
27
|
+
case wrapQuote:
|
|
28
|
+
case '\\':
|
|
29
|
+
return '\\' + character;
|
|
30
|
+
// Four possible LineTerminator characters need to be escaped:
|
|
31
|
+
case '\n':
|
|
32
|
+
return '\\n';
|
|
33
|
+
case '\r':
|
|
34
|
+
return '\\r';
|
|
35
|
+
case '\u2028':
|
|
36
|
+
return '\\u2028';
|
|
37
|
+
case '\u2029':
|
|
38
|
+
return '\\u2029';
|
|
39
|
+
default:
|
|
40
|
+
return character;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return `${wrapQuote}${escapedStr}${wrapQuote}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.logger = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Simple logger
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const logger = {
|
|
12
|
+
log: (...args) => {
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
console.log(...args);
|
|
15
|
+
},
|
|
16
|
+
error: (...args) => {
|
|
17
|
+
// eslint-disable-next-line no-console
|
|
18
|
+
console.error(...args);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.logger = logger;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _babelJest = _interopRequireDefault(require("babel-jest"));
|
|
9
|
+
var _default = _babelJest.default.createTransformer({
|
|
10
|
+
presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')],
|
|
11
|
+
plugins: [require.resolve('babel-plugin-transform-dynamic-import')]
|
|
12
|
+
});
|
|
13
|
+
exports.default = _default;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = createJestRunner;
|
|
8
|
+
var _child_process = require("child_process");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _rootPath = require("../../../utils/rootPath");
|
|
1
11
|
// import { run } from 'jest';
|
|
2
12
|
|
|
3
13
|
// function createJestRunner() {
|
|
4
|
-
// let config
|
|
14
|
+
// let config from '../configs/jest.config');
|
|
5
15
|
|
|
6
16
|
// let argv = process.argv.slice(2);
|
|
7
17
|
|
|
@@ -9,25 +19,19 @@
|
|
|
9
19
|
// run(argv);
|
|
10
20
|
// }
|
|
11
21
|
|
|
12
|
-
|
|
13
22
|
// export default createJestRunner;
|
|
14
23
|
|
|
15
|
-
const
|
|
16
|
-
const path = require('path');
|
|
17
|
-
const { getExecutableBinaryPath } = require('../../../utils/rootPath');
|
|
18
|
-
|
|
19
|
-
const jestPath = path.resolve(getExecutableBinaryPath('jest'));
|
|
24
|
+
const jestPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('jest'));
|
|
20
25
|
|
|
21
26
|
// Command and arguments for npx playwright test
|
|
22
27
|
const command = jestPath;
|
|
23
28
|
const args = ['--config', require.resolve('../../../../jest.config.js')];
|
|
24
|
-
|
|
25
|
-
|
|
26
29
|
function createJestRunner() {
|
|
27
30
|
// Spawn the child process
|
|
28
31
|
|
|
29
|
-
const childProcess = spawn(command, args, {
|
|
30
|
-
|
|
32
|
+
const childProcess = (0, _child_process.spawn)(command, args, {
|
|
33
|
+
stdio: 'inherit'
|
|
34
|
+
});
|
|
31
35
|
|
|
32
36
|
// Handling the 'exit' event of the child process
|
|
33
37
|
// childProcess.on('exit', (code, signal) => {
|
|
@@ -38,7 +42,4 @@ function createJestRunner() {
|
|
|
38
42
|
// childProcess.on('error', (err) => {
|
|
39
43
|
// console.error(`Error while spawning child process: ${err.message}`);
|
|
40
44
|
// });
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
module.exports = createJestRunner;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));
|
|
5
|
+
var _globals = require("@jest/globals");
|
|
6
|
+
var _react = _interopRequireDefault(require("react"));
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
9
|
+
require("@testing-library/jest-dom/extend-expect");
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = generateCodegen;
|
|
8
|
+
var _child_process = require("child_process");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _test = require("@playwright/test");
|
|
11
|
+
var _logger = require("../../utils/logger");
|
|
12
|
+
var _rootPath = require("../../utils/rootPath");
|
|
13
|
+
const userArgs = process.argv.slice(3);
|
|
14
|
+
const playwrightPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('playwright'));
|
|
15
|
+
const command = playwrightPath;
|
|
16
|
+
const args = ['codegen'].concat(userArgs);
|
|
17
|
+
function generateCodegen() {
|
|
18
|
+
const childProcess = (0, _child_process.spawn)(command, args, {
|
|
19
|
+
stdio: 'inherit'
|
|
20
|
+
});
|
|
21
|
+
childProcess.on('error', error => {
|
|
22
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, error);
|
|
23
|
+
});
|
|
24
|
+
childProcess.on('exit', (code, signal) => {
|
|
25
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
|
|
26
|
+
process.exit();
|
|
27
|
+
});
|
|
28
|
+
process.on('exit', () => {
|
|
29
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Terminating Playwright Process...');
|
|
30
|
+
//childProcess.kill();
|
|
31
|
+
return;
|
|
32
|
+
});
|
|
33
|
+
process.on('SIGINT', () => {
|
|
34
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Cleaning up...');
|
|
35
|
+
//childProcess.kill();
|
|
36
|
+
process.exit();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Another way to record. Below way will load the url in autheticated state if present
|
|
41
|
+
// function generateCodegen() {
|
|
42
|
+
// (async () => {
|
|
43
|
+
// // Make sure to run headed.
|
|
44
|
+
// const browser = await chromium.launch({ headless: false });
|
|
45
|
+
|
|
46
|
+
// // Setup context however you like.
|
|
47
|
+
// const context = await browser.newContext({ storageState: path.resolve(process.cwd(), 'uat', 'playwright/.auth/user.json') });
|
|
48
|
+
// await context.route('**/*', route => route.continue());
|
|
49
|
+
|
|
50
|
+
// // Pause the page, and start recording manually.
|
|
51
|
+
// const page = await context.newPage();
|
|
52
|
+
// console.log(userArgs.join(''));
|
|
53
|
+
// await page.goto(`https://${userArgs.join('')}`);
|
|
54
|
+
// await page.pause();
|
|
55
|
+
// })();
|
|
56
|
+
// }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.initializeEnvConfig = initializeEnvConfig;
|
|
8
|
+
var _fs = require("fs");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
function initializeEnvConfig(mode = 'dev') {
|
|
11
|
+
try {
|
|
12
|
+
const configFile = (0, _fs.readFileSync)(_path.default.resolve(process.cwd(), './uat/env-config.json'));
|
|
13
|
+
const configJSON = JSON.parse(configFile);
|
|
14
|
+
process.env.mode = mode;
|
|
15
|
+
for (const key in configJSON[mode]) {
|
|
16
|
+
process.env[key] = configJSON[mode][key];
|
|
17
|
+
}
|
|
18
|
+
} catch (err) {
|
|
19
|
+
throw new Error('Config File Not Exists. Please provide a config file to intiailize the environment variables');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.When = exports.Then = exports.Given = void 0;
|
|
7
|
+
Object.defineProperty(exports, "createBdd", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _bddFramework.createBdd;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "expect", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _test.expect;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
exports.test = void 0;
|
|
20
|
+
var _bddFramework = require("../../bdd-framework");
|
|
21
|
+
var _test = require("@playwright/test");
|
|
22
|
+
var _readConfigFile = require("./readConfigFile");
|
|
2
23
|
// function test(descrition, callback) {
|
|
3
24
|
// return test(descrition, ({ page }) => {
|
|
4
25
|
// const { locator, ...custompage } = page
|
|
@@ -17,13 +38,11 @@ const { expect, test: base } = require('@playwright/test');
|
|
|
17
38
|
// return this.page['goto'](...args);
|
|
18
39
|
// }
|
|
19
40
|
|
|
20
|
-
|
|
21
41
|
// getByRole(...args) {
|
|
22
42
|
// return this.page['getByRole'](...args);
|
|
23
43
|
// }
|
|
24
44
|
// }
|
|
25
45
|
|
|
26
|
-
|
|
27
46
|
// function FilteredPage(page) {
|
|
28
47
|
// return {
|
|
29
48
|
// getByRole: () => {
|
|
@@ -31,9 +50,16 @@ const { expect, test: base } = require('@playwright/test');
|
|
|
31
50
|
// }
|
|
32
51
|
// }
|
|
33
52
|
// }
|
|
34
|
-
|
|
53
|
+
const {
|
|
54
|
+
additionalPages = {},
|
|
55
|
+
bddMode
|
|
56
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
57
|
+
let base = bddMode ? _bddFramework.test : _test.test;
|
|
35
58
|
const test = base.extend({
|
|
36
|
-
page: async ({
|
|
59
|
+
page: async ({
|
|
60
|
+
baseURL,
|
|
61
|
+
page
|
|
62
|
+
}, use) => {
|
|
37
63
|
// const proxyPage = new Proxy(page, {
|
|
38
64
|
// get: function (obj, prop) {
|
|
39
65
|
// console.log('Gettig Priop', prop);
|
|
@@ -50,33 +76,37 @@ const test = base.extend({
|
|
|
50
76
|
return `${process.env.domain}?devURL=${process.env.devUrl}`;
|
|
51
77
|
}
|
|
52
78
|
return `${process.env.domain}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
79
|
+
};
|
|
55
80
|
page.getCustomPageUrl = function (url) {
|
|
56
81
|
if (process.env.mode === 'dev') {
|
|
57
|
-
return `${process.env.domain}/${url}?devURL=${process.env.devUrl}
|
|
82
|
+
return `${process.env.domain}/${url}?devURL=${process.env.devUrl}`;
|
|
58
83
|
}
|
|
59
|
-
return `${process.env.domain}/${url}
|
|
60
|
-
}
|
|
84
|
+
return `${process.env.domain}/${url}`;
|
|
85
|
+
};
|
|
61
86
|
await use(page);
|
|
62
87
|
|
|
63
|
-
|
|
64
88
|
//await use(new FilteredPage(page));
|
|
65
89
|
|
|
66
90
|
// await use(async (page) => {
|
|
67
91
|
// delete page.getByTestId;
|
|
68
92
|
// await page;
|
|
69
93
|
// });
|
|
70
|
-
|
|
71
94
|
},
|
|
72
|
-
|
|
95
|
+
|
|
96
|
+
context: async ({
|
|
97
|
+
context
|
|
98
|
+
}, use) => {
|
|
73
99
|
await context.addInitScript(() => window.localStorage.setItem('isDnBannerHide', true));
|
|
74
100
|
await use(context);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
},
|
|
102
|
+
...additionalPages
|
|
103
|
+
});
|
|
104
|
+
exports.test = test;
|
|
105
|
+
const {
|
|
106
|
+
Given,
|
|
107
|
+
When,
|
|
108
|
+
Then
|
|
109
|
+
} = (0, _bddFramework.createBdd)();
|
|
110
|
+
exports.Then = Then;
|
|
111
|
+
exports.When = When;
|
|
112
|
+
exports.Given = Given;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.fileName = void 0;
|
|
8
|
+
exports.generateConfigFromFile = generateConfigFromFile;
|
|
9
|
+
exports.getAuthFilePath = getAuthFilePath;
|
|
10
|
+
exports.isUserConfigFileAvailable = isUserConfigFileAvailable;
|
|
11
|
+
var _fs = require("fs");
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
var _logger = require("../../utils/logger");
|
|
14
|
+
const fileName = 'uat.config.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the user configuration object.
|
|
18
|
+
* @typedef {Object} UserConfig
|
|
19
|
+
* @property {string} headless - Headless Browsers mode.
|
|
20
|
+
* @property {number} trace - trace for test cases.
|
|
21
|
+
* @property {boolean} video - video for test cases,
|
|
22
|
+
* @property {boolean} debug - debug mode
|
|
23
|
+
* @property {string} mode: mode in which the test cases needs to run
|
|
24
|
+
* @property {boolean} isAuthMode - Auth Mode
|
|
25
|
+
* @property {any} browsers: List of browsers
|
|
26
|
+
* @property {string} openReportOn: default Option value (never, on-failure and always)
|
|
27
|
+
* @property {any} reportPath : directory where report is generate
|
|
28
|
+
* @property {boolean} bddMode: Feature files needs to be processed
|
|
29
|
+
* @property {number} expectTimeout: time in milliseconds which the expect condition should fail
|
|
30
|
+
* @property {number} testTimeout: time in milliseconds which the test should fail
|
|
31
|
+
* @property {Object} additionalPages: custom pages configuration
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Generates a configuration object from a file, if it exists.
|
|
36
|
+
*
|
|
37
|
+
* @returns {UserConfig}
|
|
38
|
+
*/
|
|
39
|
+
exports.fileName = fileName;
|
|
40
|
+
function generateConfigFromFile() {
|
|
41
|
+
const filePath = _path.default.resolve(process.cwd(), fileName);
|
|
42
|
+
if ((0, _fs.existsSync)(filePath)) {
|
|
43
|
+
/** @type {UserConfig} */
|
|
44
|
+
const config = require(filePath);
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
function isUserConfigFileAvailable() {
|
|
50
|
+
const filePath = _path.default.resolve(process.cwd(), fileName);
|
|
51
|
+
if ((0, _fs.existsSync)(filePath)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
function getAuthFilePath(filePath) {
|
|
57
|
+
try {
|
|
58
|
+
if ((0, _fs.existsSync)(filePath)) {
|
|
59
|
+
return filePath;
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Founded Path - ${filePath} Authetication file not Exist ...`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = generateReport;
|
|
8
|
+
var _child_process = require("child_process");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _logger = require("../../utils/logger");
|
|
11
|
+
var _rootPath = require("../../utils/rootPath");
|
|
12
|
+
var _readConfigFile = require("./readConfigFile");
|
|
13
|
+
const userArgs = process.argv.slice(3);
|
|
14
|
+
const playwrightPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('playwright'));
|
|
15
|
+
;
|
|
16
|
+
const command = playwrightPath;
|
|
17
|
+
const {
|
|
18
|
+
reportPath: htmlPath = _path.default.resolve(process.cwd(), './playwright-report')
|
|
19
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
20
|
+
const reportPath = htmlPath;
|
|
21
|
+
const args = ['show-report', htmlPath].concat(userArgs);
|
|
22
|
+
function generateReport() {
|
|
23
|
+
const childProcess = (0, _child_process.spawn)(command, args, {
|
|
24
|
+
stdio: 'inherit'
|
|
25
|
+
});
|
|
26
|
+
childProcess.on('error', error => {
|
|
27
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, error);
|
|
28
|
+
});
|
|
29
|
+
childProcess.on('exit', (code, signal) => {
|
|
30
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
|
|
31
|
+
process.exit();
|
|
32
|
+
});
|
|
33
|
+
process.on('exit', () => {
|
|
34
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Terminating Playwright Process...');
|
|
35
|
+
childProcess.kill();
|
|
36
|
+
return;
|
|
37
|
+
});
|
|
38
|
+
process.on('SIGINT', () => {
|
|
39
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Cleaning up...');
|
|
40
|
+
childProcess.kill();
|
|
41
|
+
process.exit();
|
|
42
|
+
});
|
|
43
|
+
}
|