@zohodesk/testinglibrary 0.1.4 → 0.1.5
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/.eslintrc.js +1 -1
- package/build/bdd-framework/cli/commands/env.js +1 -2
- package/build/bdd-framework/cli/commands/export.js +1 -2
- package/build/bdd-framework/cli/commands/test.js +1 -2
- package/build/bdd-framework/cli/options.js +1 -2
- package/build/bdd-framework/config/index.js +1 -2
- package/build/bdd-framework/decorators.js +4 -8
- package/build/bdd-framework/playwright/utils.js +1 -4
- package/build/bdd-framework/run/bddFixtures.js +1 -2
- package/build/bdd-framework/snippets/index.js +0 -1
- package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -1
- package/build/bdd-framework/stepDefinitions/decorators/steps.js +0 -1
- package/build/bdd-framework/utils/logger.js +1 -2
- package/build/core/jest/preprocessor/jsPreprocessor.js +2 -3
- package/build/core/playwright/clear-caches.js +29 -0
- package/build/core/playwright/custom-commands.js +1 -2
- package/build/core/playwright/index.js +1 -3
- package/build/core/playwright/readConfigFile.js +1 -2
- package/build/core/playwright/setup/config-creator.js +2 -3
- package/build/core/playwright/setup/custom-reporter.js +100 -0
- package/build/core/playwright/test-runner.js +3 -5
- package/build/index.d.ts +58 -3
- package/build/index.js +4 -2
- package/build/lib/cli.js +10 -1
- package/build/parser/parser.js +0 -1
- package/build/setup-folder-structure/helper.js +34 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +8 -4
- package/build/setup-folder-structure/setupProject.js +10 -5
- package/build/utils/fileUtils.js +12 -0
- package/build/utils/logger.js +1 -2
- package/build/utils/stepDefinitionsFormatter.js +1 -2
- package/changelog.md +22 -0
- package/npm-shrinkwrap.json +968 -2280
- package/package.json +6 -5
package/.eslintrc.js
CHANGED
|
@@ -15,7 +15,7 @@ var _loadConfig = require("../../playwright/loadConfig");
|
|
|
15
15
|
const logger = new _logger.Logger({
|
|
16
16
|
verbose: true
|
|
17
17
|
});
|
|
18
|
-
const envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
|
|
18
|
+
const envCommand = exports.envCommand = new _commander.Command('env').description('Prints environment info').addOption(_options.configOption).action(opts => {
|
|
19
19
|
logger.log(`Playwright-bdd environment info:\n`);
|
|
20
20
|
logger.log(`platform: ${process.platform}`);
|
|
21
21
|
logger.log(`node: ${process.version}`);
|
|
@@ -24,7 +24,6 @@ const envCommand = new _commander.Command('env').description('Prints environment
|
|
|
24
24
|
showPackageVersion('@cucumber/cucumber');
|
|
25
25
|
showPlaywrightConfigPath(opts.config);
|
|
26
26
|
});
|
|
27
|
-
exports.envCommand = envCommand;
|
|
28
27
|
function showPackageVersion(packageName) {
|
|
29
28
|
const version = packageName === 'playwright-bdd' ? getOwnVersion() : (0, _utils.getPackageVersion)(packageName);
|
|
30
29
|
logger.log(`${packageName}: v${version}`);
|
|
@@ -16,7 +16,7 @@ var _gen = require("../../gen");
|
|
|
16
16
|
const logger = new _logger.Logger({
|
|
17
17
|
verbose: true
|
|
18
18
|
});
|
|
19
|
-
const exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
|
|
19
|
+
const exportCommand = exports.exportCommand = new _commander.Command('export').description('Prints all step definitions').addOption(_options.configOption).action(async opts => {
|
|
20
20
|
const {
|
|
21
21
|
resolvedConfigFile
|
|
22
22
|
} = await (0, _loadConfig.loadConfig)(opts.config);
|
|
@@ -25,7 +25,6 @@ const exportCommand = new _commander.Command('export').description('Prints all s
|
|
|
25
25
|
(0, _test.assertConfigsCount)(configs);
|
|
26
26
|
await showStepsForConfigs(configs);
|
|
27
27
|
});
|
|
28
|
-
exports.exportCommand = exportCommand;
|
|
29
28
|
async function showStepsForConfigs(configs) {
|
|
30
29
|
// here we don't need workers (as in test command) because if some step files
|
|
31
30
|
// are already in node cache, we collected them.
|
|
@@ -17,13 +17,12 @@ var _config = require("../../config");
|
|
|
17
17
|
var _options = require("../options");
|
|
18
18
|
var _exit = require("../../utils/exit");
|
|
19
19
|
const GEN_WORKER_PATH = _path.default.resolve(__dirname, '..', 'worker.js');
|
|
20
|
-
const testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
|
|
20
|
+
const testCommand = exports.testCommand = new _commander.Command('test').description('Generate Playwright test files from Gherkin documents').addOption(_options.configOption).option('--tags <expression>', `Tags expression to filter scenarios for generation`).option('--verbose', `Verbose mode (default: ${Boolean(_config.defaults.verbose)})`).action(async opts => {
|
|
21
21
|
await (0, _loadConfig.loadConfig)(opts.config);
|
|
22
22
|
const configs = readConfigsFromEnv();
|
|
23
23
|
mergeCliOptions(configs, opts);
|
|
24
24
|
await generateFilesForConfigs(configs);
|
|
25
25
|
});
|
|
26
|
-
exports.testCommand = testCommand;
|
|
27
26
|
function readConfigsFromEnv() {
|
|
28
27
|
const configs = Object.values((0, _env.getEnvConfigs)());
|
|
29
28
|
assertConfigsCount(configs);
|
|
@@ -10,11 +10,10 @@ var _commander = require("commander");
|
|
|
10
10
|
* Config option moved to separate file as it used in test run.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
|
|
13
|
+
const configOption = exports.configOption = new _commander.Option(`-c, --config <file>`, `Path to Playwright configuration file (default: playwright.config.(js|ts))`);
|
|
14
14
|
/**
|
|
15
15
|
* Helper used in test run to detect config location.
|
|
16
16
|
*/
|
|
17
|
-
exports.configOption = configOption;
|
|
18
17
|
function getCliConfigPath() {
|
|
19
18
|
return new _commander.Command().allowUnknownOption().addOption(configOption).parse().getOptionValue('config');
|
|
20
19
|
}
|
|
@@ -15,14 +15,13 @@ var _utils = require("../utils");
|
|
|
15
15
|
* BDD Config.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
const defaults = {
|
|
18
|
+
const defaults = exports.defaults = {
|
|
19
19
|
outputDir: '.features-gen',
|
|
20
20
|
verbose: false,
|
|
21
21
|
examplesTitleFormat: 'Example #<_index_>',
|
|
22
22
|
publishQuiet: true,
|
|
23
23
|
quotes: 'double'
|
|
24
24
|
};
|
|
25
|
-
exports.defaults = defaults;
|
|
26
25
|
function defineBddConfig(inputConfig) {
|
|
27
26
|
const config = getConfig(inputConfig);
|
|
28
27
|
// In main process store config in env to be accessible by workers
|
|
@@ -12,11 +12,7 @@ Object.defineProperty(exports, "Fixture", {
|
|
|
12
12
|
exports.When = exports.Then = exports.Step = exports.Given = void 0;
|
|
13
13
|
var _poms = require("./stepDefinitions/decorators/poms");
|
|
14
14
|
var _steps = require("./stepDefinitions/decorators/steps");
|
|
15
|
-
const Given = (0, _steps.createStepDecorator)('Given');
|
|
16
|
-
exports.
|
|
17
|
-
const
|
|
18
|
-
exports.
|
|
19
|
-
const Then = (0, _steps.createStepDecorator)('Then');
|
|
20
|
-
exports.Then = Then;
|
|
21
|
-
const Step = (0, _steps.createStepDecorator)('Unknown');
|
|
22
|
-
exports.Step = Step;
|
|
15
|
+
const Given = exports.Given = (0, _steps.createStepDecorator)('Given');
|
|
16
|
+
const When = exports.When = (0, _steps.createStepDecorator)('When');
|
|
17
|
+
const Then = exports.Then = (0, _steps.createStepDecorator)('Then');
|
|
18
|
+
const Step = exports.Step = (0, _steps.createStepDecorator)('Unknown');
|
|
@@ -28,10 +28,7 @@ function getPlaywrightRoot() {
|
|
|
28
28
|
// See: https://github.com/microsoft/playwright/pull/26946
|
|
29
29
|
const playwrightTestRoot = (0, _utils.resolvePackageRoot)('@playwright/test');
|
|
30
30
|
const libDir = _path.default.join(playwrightTestRoot, 'lib');
|
|
31
|
-
|
|
32
|
-
// Recently added functionality in playwright
|
|
33
|
-
const playwrightDir = _path.default.join(playwrightTestRoot, 'node_modules', 'playwright');
|
|
34
|
-
playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : playwrightDir;
|
|
31
|
+
playwrightRoot = _fs.default.existsSync(libDir) ? playwrightTestRoot : (0, _utils.resolvePackageRoot)('playwright');
|
|
35
32
|
}
|
|
36
33
|
return playwrightRoot;
|
|
37
34
|
}
|
|
@@ -13,7 +13,7 @@ var _config = require("../config");
|
|
|
13
13
|
var _env = require("../config/env");
|
|
14
14
|
var _steps = require("../stepDefinitions/decorators/steps");
|
|
15
15
|
var _dir = require("../config/dir");
|
|
16
|
-
const test = _test.test.extend({
|
|
16
|
+
const test = exports.test = _test.test.extend({
|
|
17
17
|
$bddWorldBase: async ({
|
|
18
18
|
$tags,
|
|
19
19
|
$test
|
|
@@ -101,7 +101,6 @@ const test = _test.test.extend({
|
|
|
101
101
|
// eslint-disable-next-line
|
|
102
102
|
$test: ({}, use) => use(_test.test)
|
|
103
103
|
});
|
|
104
|
-
exports.test = test;
|
|
105
104
|
const BDD_AUTO_INJECT_FIXTURES = ['$testInfo', '$test', '$tags'];
|
|
106
105
|
function isBddAutoInjectFixture(name) {
|
|
107
106
|
return BDD_AUTO_INJECT_FIXTURES.includes(name);
|
|
@@ -65,7 +65,6 @@ function appendDecoratorSteps(supportCodeLibrary) {
|
|
|
65
65
|
decoratedSteps.clear();
|
|
66
66
|
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
67
67
|
}
|
|
68
|
-
|
|
69
68
|
function getPomNodeByFixtureName(fixtureName) {
|
|
70
69
|
for (const pomNode of pomGraph.values()) {
|
|
71
70
|
if (pomNode.fixtureName === fixtureName) return pomNode;
|
|
@@ -73,7 +73,6 @@ function appendDecoratorSteps(supportCodeLibrary) {
|
|
|
73
73
|
decoratedSteps.clear();
|
|
74
74
|
// todo: fill supportCodeLibrary.originalCoordinates as it is used in snippets?
|
|
75
75
|
}
|
|
76
|
-
|
|
77
76
|
function getFirstNonAutoInjectFixture(fixturesArg, stepConfig) {
|
|
78
77
|
// there should be exatcly one suitable fixture in fixturesArg
|
|
79
78
|
const fixtureNames = Object.keys(fixturesArg).filter(fixtureName => !(0, _bddFixtures.isBddAutoInjectFixture)(fixtureName));
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _babelJest = _interopRequireDefault(require("babel-jest"));
|
|
9
|
-
var _default = _babelJest.default.createTransformer({
|
|
9
|
+
var _default = exports.default = _babelJest.default.createTransformer({
|
|
10
10
|
presets: [require.resolve('@babel/preset-env'), require.resolve('@babel/preset-react')],
|
|
11
11
|
plugins: [require.resolve('babel-plugin-transform-dynamic-import')]
|
|
12
|
-
});
|
|
13
|
-
exports.default = _default;
|
|
12
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _fileUtils = require("../../utils/fileUtils");
|
|
10
|
+
var _logger = require("../../utils/logger");
|
|
11
|
+
var _readConfigFile = require("./readConfigFile");
|
|
12
|
+
function clearCaches() {
|
|
13
|
+
try {
|
|
14
|
+
const {
|
|
15
|
+
authFilePath,
|
|
16
|
+
reportPath
|
|
17
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
18
|
+
authFilePath.split('/').pop();
|
|
19
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting auth files present in ${authFilePath}`);
|
|
20
|
+
(0, _fileUtils.deleteFolder)(_path.default.resolve(process.cwd(), authFilePath));
|
|
21
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting Playwright report ${reportPath}`);
|
|
22
|
+
(0, _fileUtils.deleteFolder)(reportPath);
|
|
23
|
+
(0, _fileUtils.deleteFolder)(_path.default.resolve(process.cwd(), 'uat', '.features-gen'));
|
|
24
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Caches Cleared');
|
|
25
|
+
} catch (err) {
|
|
26
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Error While clearing cookies');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var _default = exports.default = clearCaches;
|
|
@@ -55,7 +55,7 @@ const {
|
|
|
55
55
|
bddMode
|
|
56
56
|
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
57
57
|
let base = bddMode ? _bddFramework.test : _test.test;
|
|
58
|
-
const test = base.extend({
|
|
58
|
+
const test = exports.test = base.extend({
|
|
59
59
|
page: async ({
|
|
60
60
|
page
|
|
61
61
|
}, use) => {
|
|
@@ -91,7 +91,6 @@ const test = base.extend({
|
|
|
91
91
|
// await page;
|
|
92
92
|
// });
|
|
93
93
|
},
|
|
94
|
-
|
|
95
94
|
context: async ({
|
|
96
95
|
context
|
|
97
96
|
}, use) => {
|
|
@@ -101,7 +100,6 @@ const test = base.extend({
|
|
|
101
100
|
},
|
|
102
101
|
...additionalPages
|
|
103
102
|
});
|
|
104
|
-
exports.test = test;
|
|
105
103
|
const {
|
|
106
104
|
Given,
|
|
107
105
|
When,
|
|
@@ -11,8 +11,7 @@ exports.isUserConfigFileAvailable = isUserConfigFileAvailable;
|
|
|
11
11
|
var _fs = require("fs");
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
13
|
var _logger = require("../../utils/logger");
|
|
14
|
-
const fileName = 'uat.config.js';
|
|
15
|
-
exports.fileName = fileName;
|
|
14
|
+
const fileName = exports.fileName = 'uat.config.js';
|
|
16
15
|
function getDefaultConfig() {
|
|
17
16
|
return {
|
|
18
17
|
headless: false,
|
|
@@ -60,7 +60,7 @@ function getPlaywrightConfig() {
|
|
|
60
60
|
reporter: [['html', {
|
|
61
61
|
outputFolder: reportPath,
|
|
62
62
|
open: openReportOn
|
|
63
|
-
}]],
|
|
63
|
+
}], ['list'], ['./custom-reporter.js']],
|
|
64
64
|
timeout: testTimeout,
|
|
65
65
|
expect: {
|
|
66
66
|
timeout: expectTimeout
|
|
@@ -73,5 +73,4 @@ function getPlaywrightConfig() {
|
|
|
73
73
|
}, ...projects] : [...projects]
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
var _default = (0, _test.defineConfig)(getPlaywrightConfig());
|
|
77
|
-
exports.default = _default;
|
|
76
|
+
var _default = exports.default = (0, _test.defineConfig)(getPlaywrightConfig());
|
|
@@ -0,0 +1,100 @@
|
|
|
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 _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _readline = _interopRequireDefault(require("readline"));
|
|
10
|
+
var _fileUtils = require("../../../utils/fileUtils");
|
|
11
|
+
var _readConfigFile = require("../readConfigFile");
|
|
12
|
+
var _logger = require("../../../utils/logger");
|
|
13
|
+
class JSONSummaryReporter {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.durationInMS = -1;
|
|
16
|
+
this.passed = [];
|
|
17
|
+
this.skipped = [];
|
|
18
|
+
this.failed = [];
|
|
19
|
+
this.warned = [];
|
|
20
|
+
this.interrupted = [];
|
|
21
|
+
this.timedOut = [];
|
|
22
|
+
this.flakey = [];
|
|
23
|
+
this.status = 'unknown';
|
|
24
|
+
this.startedAt = 0;
|
|
25
|
+
this._open = (0, _readConfigFile.generateConfigFromFile)().openReportOn;
|
|
26
|
+
}
|
|
27
|
+
onBegin() {
|
|
28
|
+
this.startedAt = Date.now();
|
|
29
|
+
}
|
|
30
|
+
onTestEnd(test, result) {
|
|
31
|
+
const title = [];
|
|
32
|
+
const fileName = [];
|
|
33
|
+
let clean = true;
|
|
34
|
+
for (const s of test.titlePath()) {
|
|
35
|
+
if (s === '' && clean) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
clean = false;
|
|
39
|
+
title.push(s);
|
|
40
|
+
if (s.includes('.ts') || s.includes('.js')) {
|
|
41
|
+
fileName.push(s);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// This will publish the file name + line number test begins on
|
|
45
|
+
const z = `${fileName[0]}:${test.location.line}:${test.location.column}`;
|
|
46
|
+
// Using the t variable in the push will push a full test name + test description
|
|
47
|
+
const t = title.join(' > ');
|
|
48
|
+
// Set the status
|
|
49
|
+
const status = !['passed', 'skipped'].includes(result.status) && t.includes('@warn') ? 'warned' : result.status;
|
|
50
|
+
// Logic to push the results into the correct array
|
|
51
|
+
if (result.status === 'passed' && result.retry >= 1) {
|
|
52
|
+
this.flakey.push(z);
|
|
53
|
+
} else {
|
|
54
|
+
this[status].push(z);
|
|
55
|
+
}
|
|
56
|
+
this[status].push(z);
|
|
57
|
+
}
|
|
58
|
+
onEnd(result) {
|
|
59
|
+
this.durationInMS = Date.now() - this.startedAt;
|
|
60
|
+
this.status = result.status;
|
|
61
|
+
// removing duplicate tests from passed array
|
|
62
|
+
this.passed = this.passed.filter((element, index) => {
|
|
63
|
+
return this.passed.indexOf(element) === index;
|
|
64
|
+
});
|
|
65
|
+
// removing duplicate tests from the failed array
|
|
66
|
+
this.failed = this.failed.filter((element, index) => {
|
|
67
|
+
if (!this.passed.includes(element)) {
|
|
68
|
+
return this.failed.indexOf(element) === index;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// removing duplicate tests from the skipped array
|
|
72
|
+
this.skipped = this.skipped.filter((element, index) => {
|
|
73
|
+
return this.skipped.indexOf(element) === index;
|
|
74
|
+
});
|
|
75
|
+
// removing duplicate tests from the timedOut array
|
|
76
|
+
this.timedOut = this.timedOut.filter((element, index) => {
|
|
77
|
+
return this.timedOut.indexOf(element) === index;
|
|
78
|
+
});
|
|
79
|
+
// removing duplicate tests from the interrupted array
|
|
80
|
+
this.interrupted = this.interrupted.filter((element, index) => {
|
|
81
|
+
return this.interrupted.indexOf(element) === index;
|
|
82
|
+
});
|
|
83
|
+
// fs.writeFileSync('./summary.json', JSON.stringify(this, null, ' '));
|
|
84
|
+
let {
|
|
85
|
+
reportPath
|
|
86
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
87
|
+
(0, _fileUtils.writeFileContents)(_path.default.join(reportPath, './', 'test-summary.json'), JSON.stringify(this, null, ' '));
|
|
88
|
+
}
|
|
89
|
+
onExit() {
|
|
90
|
+
const shouldClearLastLine = this._open !== 'always' || this._open !== 'on-failure';
|
|
91
|
+
if (shouldClearLastLine) {
|
|
92
|
+
/**Below code is to replace the playwright default report commond with abstraction tool command */
|
|
93
|
+
_readline.default.moveCursor(process.stdout, 0, -2); // up two line
|
|
94
|
+
_readline.default.clearLine(process.stdout, 1); // from cursor to end
|
|
95
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'npx ZDTestingFramework report or npm run uat-report');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
var _default = exports.default = JSONSummaryReporter;
|
|
@@ -66,7 +66,6 @@ function runPlaywright(command, args) {
|
|
|
66
66
|
});
|
|
67
67
|
childProcessForRunningPlaywright.on('exit', (code, signal) => {
|
|
68
68
|
if (code !== 0) {
|
|
69
|
-
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Child Process Exited with Code ${code} and Signal ${signal}`);
|
|
70
69
|
reject(`Child Process Exited with Code ${code} and Signal ${signal}`);
|
|
71
70
|
} else {
|
|
72
71
|
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Test Ran Successfully');
|
|
@@ -74,11 +73,11 @@ function runPlaywright(command, args) {
|
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
process.on('exit', () => {
|
|
77
|
-
|
|
76
|
+
childProcessForRunningPlaywright.kill();
|
|
78
77
|
reject('Terminating Playwright Process...');
|
|
79
78
|
});
|
|
80
79
|
process.on('SIGINT', () => {
|
|
81
|
-
|
|
80
|
+
childProcessForRunningPlaywright.kill();
|
|
82
81
|
reject('Cleaning up...');
|
|
83
82
|
});
|
|
84
83
|
});
|
|
@@ -108,5 +107,4 @@ function main() {
|
|
|
108
107
|
process.exit();
|
|
109
108
|
});
|
|
110
109
|
}
|
|
111
|
-
var _default = main;
|
|
112
|
-
exports.default = _default;
|
|
110
|
+
var _default = exports.default = main;
|
package/build/index.d.ts
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expect, test } from './core/playwright/index';
|
|
2
2
|
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
+
import {
|
|
4
|
+
PlaywrightTestArgs,
|
|
5
|
+
PlaywrightTestOptions,
|
|
6
|
+
PlaywrightWorkerArgs,
|
|
7
|
+
PlaywrightWorkerOptions,
|
|
8
|
+
TestType,
|
|
9
|
+
Page
|
|
10
|
+
} from '@playwright/test';
|
|
11
|
+
import { DefineStepPattern } from '@cucumber/cucumber/lib/support_code_library_builder/types';
|
|
3
12
|
|
|
4
|
-
export
|
|
5
|
-
|
|
13
|
+
export type KeyValue = { [key: string]: any };
|
|
14
|
+
|
|
15
|
+
export type BuiltInFixturesWorker = PlaywrightWorkerArgs &
|
|
16
|
+
PlaywrightWorkerOptions;
|
|
17
|
+
export type BuiltInFixtures = PlaywrightTestArgs &
|
|
18
|
+
PlaywrightTestOptions &
|
|
19
|
+
BuiltInFixturesWorker;
|
|
20
|
+
|
|
21
|
+
export type FixturesArg<T extends KeyValue = {}, W extends KeyValue = {}> = T &
|
|
22
|
+
W &
|
|
23
|
+
BuiltInFixtures;
|
|
24
|
+
|
|
25
|
+
export declare let hasCustomTest: boolean;
|
|
26
|
+
|
|
27
|
+
export declare function createBdd<
|
|
28
|
+
T extends KeyValue = BuiltInFixtures,
|
|
29
|
+
W extends KeyValue = BuiltInFixturesWorker,
|
|
30
|
+
World
|
|
31
|
+
>(
|
|
32
|
+
customTest?: TestType<T, W> | null,
|
|
33
|
+
_CustomWorld?: new (...args: any[]) => World
|
|
34
|
+
): {
|
|
35
|
+
Given: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
36
|
+
When: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
37
|
+
Then: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
38
|
+
And: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
39
|
+
But: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
40
|
+
Step: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
41
|
+
Before: any;
|
|
42
|
+
After: any;
|
|
43
|
+
BeforeAll: any;
|
|
44
|
+
AfterAll: any;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type StepFunctionFixturesArg<
|
|
48
|
+
T extends KeyValue,
|
|
49
|
+
W extends KeyValue
|
|
50
|
+
> = FixturesArg<T, W>;
|
|
51
|
+
type StepFunction<T extends KeyValue, W extends KeyValue> = (
|
|
52
|
+
fixtures: StepFunctionFixturesArg<T, W>,
|
|
53
|
+
...args: any[]
|
|
54
|
+
) => unknown;
|
|
55
|
+
|
|
56
|
+
const { Given, Then, When, Step, And, But } = createBdd();
|
|
57
|
+
|
|
58
|
+
export { Given, Then, When, Step, And, But, expect, test, createBdd, Page };
|
|
59
|
+
|
|
60
|
+
export * from '@playwright/test/types/test';
|
package/build/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.When = exports.Then = exports.Step = exports.Given = void 0;
|
|
6
|
+
exports.When = exports.Then = exports.Step = exports.Given = exports.But = exports.And = void 0;
|
|
7
7
|
Object.defineProperty(exports, "createBdd", {
|
|
8
8
|
enumerable: true,
|
|
9
9
|
get: function () {
|
|
@@ -45,4 +45,6 @@ const {
|
|
|
45
45
|
exports.Step = Step;
|
|
46
46
|
exports.When = When;
|
|
47
47
|
exports.Then = Then;
|
|
48
|
-
exports.Given = Given;
|
|
48
|
+
exports.Given = Given;
|
|
49
|
+
const And = exports.And = Then;
|
|
50
|
+
const But = exports.But = Then;
|
package/build/lib/cli.js
CHANGED
|
@@ -7,6 +7,8 @@ var _codegen = _interopRequireDefault(require("../core/playwright/codegen"));
|
|
|
7
7
|
var _logger = require("../utils/logger");
|
|
8
8
|
var _setupProject = _interopRequireDefault(require("../setup-folder-structure/setupProject"));
|
|
9
9
|
var _parser = require("../parser/parser");
|
|
10
|
+
var _clearCaches = _interopRequireDefault(require("../core/playwright/clear-caches"));
|
|
11
|
+
var _helper = _interopRequireDefault(require("../setup-folder-structure/helper"));
|
|
10
12
|
// import createJestRunner from '../core/jest/runner/jest-runner';
|
|
11
13
|
|
|
12
14
|
const [,, option, ...otherOptions] = process.argv;
|
|
@@ -46,9 +48,16 @@ switch (option) {
|
|
|
46
48
|
(0, _parser.generateSpecCodeForFeatureFile)(otherOptions);
|
|
47
49
|
break;
|
|
48
50
|
}
|
|
51
|
+
case 'clearCaches':
|
|
52
|
+
{
|
|
53
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Clearing caches...');
|
|
54
|
+
(0, _clearCaches.default)();
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case 'help':
|
|
49
58
|
default:
|
|
50
59
|
{
|
|
51
|
-
|
|
60
|
+
(0, _helper.default)();
|
|
52
61
|
break;
|
|
53
62
|
}
|
|
54
63
|
}
|
package/build/parser/parser.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
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 _commander = require("commander");
|
|
9
|
+
var _fs = require("fs");
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _logger = require("../utils/logger");
|
|
12
|
+
function helpercmd() {
|
|
13
|
+
const packageJsonPath = _path.default.resolve(process.cwd(), './package.json');
|
|
14
|
+
if ((0, _fs.existsSync)(packageJsonPath) && process.argv.includes('--version')) {
|
|
15
|
+
const {
|
|
16
|
+
dependencies
|
|
17
|
+
} = require(packageJsonPath);
|
|
18
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `zohodesk/testinglibrary Version : ${dependencies['@zohodesk/testinglibrary']}`);
|
|
19
|
+
_commander.program.version(dependencies['@zohodesk/testinglibrary'] || '0.0.1');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Supported Commands...');
|
|
23
|
+
_commander.program.name('npx ZDTestingFramework');
|
|
24
|
+
_commander.program.command('test').description('This command is used to execute tests');
|
|
25
|
+
_commander.program.command('init').description('This command will initialize Project');
|
|
26
|
+
_commander.program.command('report').description('This command is used to generate a report summarizing the results of executed tests.');
|
|
27
|
+
_commander.program.command('codegen').description('This command is used to assist developer to write test case');
|
|
28
|
+
_commander.program.option('--headed', 'Run tests with a headed browser.');
|
|
29
|
+
_commander.program.option('--debug', 'This command is used to initiate a debugging session');
|
|
30
|
+
_commander.program.option('--tags', 'Run specific test case with mentioned tags (Usage: -- --tags="@live")');
|
|
31
|
+
_commander.program.option('--workers', 'Specify number of workers to run the test case parallely (Usage: -- --workers=2)');
|
|
32
|
+
_commander.program.parse(process.argv);
|
|
33
|
+
}
|
|
34
|
+
var _default = exports.default = helpercmd;
|
|
@@ -2,15 +2,19 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { Logger } from '../utils/logger';
|
|
4
4
|
import { generateConfigFromFile } from '../core/playwright/readConfigFile';
|
|
5
|
-
|
|
5
|
+
const gitIgnoreAbsolutePath = path.resolve(process.cwd(), '../', '../')
|
|
6
6
|
|
|
7
7
|
const { reportPath = path.resolve(process.cwd(), 'uat', 'playwright-reports') } = generateConfigFromFile();
|
|
8
8
|
const testResultsPath = path.resolve(process.cwd(), 'uat', 'test-results');
|
|
9
9
|
|
|
10
|
-
const testResultsRelativepath = path.relative(
|
|
11
|
-
const reportRelativepath = path.relative(
|
|
10
|
+
const testResultsRelativepath = path.relative(gitIgnoreAbsolutePath, testResultsPath)
|
|
11
|
+
const reportRelativepath = path.relative(gitIgnoreAbsolutePath, reportPath)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const absolutePathfeaturegen = path.resolve(process.cwd(), 'uat', '.features-gen');
|
|
15
|
+
const featuregenRelativePath = path.relative(gitIgnoreAbsolutePath,absolutePathfeaturegen)
|
|
12
16
|
|
|
13
|
-
const dirpathtoIgnore = `${testResultsRelativepath}\n${reportRelativepath}`
|
|
17
|
+
const dirpathtoIgnore = `${testResultsRelativepath}\n${reportRelativepath}\n${featuregenRelativePath}`
|
|
14
18
|
|
|
15
19
|
function updateGitIgnore() {
|
|
16
20
|
if (existsSync(path.resolve(process.cwd(), '../', '../', '.gitignore'))) {
|
|
@@ -61,14 +61,18 @@ function createUatConfig() {
|
|
|
61
61
|
function createAuthenticationFile() {
|
|
62
62
|
const isUATexist = _path.default.resolve(process.cwd(), 'uat');
|
|
63
63
|
if ((0, _fs.existsSync)(isUATexist)) {
|
|
64
|
-
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Authentication File ....');
|
|
65
64
|
try {
|
|
66
|
-
(0, _fs.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
if (!(0, _fs.existsSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'))) {
|
|
66
|
+
(0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'));
|
|
67
|
+
}
|
|
68
|
+
if (!(0, _fs.existsSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'))) {
|
|
69
|
+
(0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'), {
|
|
70
|
+
recursive: true
|
|
71
|
+
});
|
|
72
|
+
}
|
|
70
73
|
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'auth.setup.js'), getSetupFileAsString('auth-setup-sample.js'), null, 2);
|
|
71
74
|
(0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'authUsers.json'), getSetupFileAsString('authUsers-sample.json'), null, 2);
|
|
75
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Authentication File ....');
|
|
72
76
|
} catch (err) {
|
|
73
77
|
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat');
|
|
74
78
|
}
|
|
@@ -91,6 +95,7 @@ function setupProject() {
|
|
|
91
95
|
createFolderForUAT();
|
|
92
96
|
createConfigJson();
|
|
93
97
|
createAuthenticationFile();
|
|
98
|
+
//updateGitIgnore()
|
|
94
99
|
// Create folder for playwright . Inside .auth folder needs to be created. user.json
|
|
95
100
|
// Add playwright and test-results to .gitignore
|
|
96
101
|
setTimeout(() => {
|
package/build/utils/fileUtils.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.checkIfFileExists = checkIfFileExists;
|
|
8
8
|
exports.deleteFile = deleteFile;
|
|
9
|
+
exports.deleteFolder = deleteFolder;
|
|
9
10
|
exports.readFileContents = readFileContents;
|
|
10
11
|
exports.writeFileContents = writeFileContents;
|
|
11
12
|
var _fs = _interopRequireDefault(require("fs"));
|
|
@@ -50,4 +51,15 @@ function deleteFile(filePath) {
|
|
|
50
51
|
throw new Error(`Error while deleting the test data file: ${filePath}`);
|
|
51
52
|
}
|
|
52
53
|
}
|
|
54
|
+
}
|
|
55
|
+
function deleteFolder(folderPath) {
|
|
56
|
+
if (_fs.default.existsSync(folderPath)) {
|
|
57
|
+
try {
|
|
58
|
+
_fs.default.rmdirSync(folderPath, {
|
|
59
|
+
recursive: true
|
|
60
|
+
});
|
|
61
|
+
} catch (err) {
|
|
62
|
+
throw new Error(`Error while deleting the test data file: ${folderPath}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
53
65
|
}
|
package/build/utils/logger.js
CHANGED