@zohodesk/testinglibrary 0.0.5-exp.9 → 0.0.5-n20-experimental
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 +9 -1
- package/.eslintrc.js +31 -0
- package/.gitlab-ci.yml +191 -0
- package/.prettierrc +6 -0
- package/README.md +151 -1
- package/build/common/data-generator/steps/DataGenerator.spec.js +19 -0
- package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +19 -0
- package/build/common/multi-actor/steps/multiActorHandling.spec.js +26 -0
- package/build/common/searchFake/helpers/rpcRequestHelper.js +41 -0
- package/build/common/searchFake/steps/searchFake.spec.js +26 -0
- package/build/core/dataGenerator/DataGenerator.js +108 -0
- package/build/core/dataGenerator/DataGeneratorError.js +50 -0
- package/build/core/dataGenerator/DataGeneratorHelper.js +49 -0
- package/build/core/jest/preprocessor/jsPreprocessor.js +3 -9
- package/build/core/jest/runner/jest-runner.js +1 -0
- package/build/core/jest/setup/index.js +1 -7
- package/build/core/playwright/builtInFixtures/actorContext.js +75 -0
- package/build/core/playwright/builtInFixtures/addTags.js +19 -0
- package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
- package/build/core/playwright/builtInFixtures/context.js +32 -0
- package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
- package/build/core/playwright/builtInFixtures/i18N.js +41 -0
- package/build/core/playwright/builtInFixtures/index.js +46 -0
- package/build/core/playwright/builtInFixtures/page.js +38 -0
- package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
- package/build/core/playwright/clear-caches.js +49 -0
- package/build/core/playwright/codegen.js +5 -6
- package/build/core/playwright/configuration/Configuration.js +25 -0
- package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
- package/build/core/playwright/configuration/UserArgs.js +12 -0
- package/build/core/playwright/constants/browserTypes.js +12 -0
- package/build/core/playwright/constants/fileMutexConfig.js +9 -0
- package/build/core/playwright/custom-commands.js +1 -2
- package/build/core/playwright/env-initializer.js +28 -6
- package/build/core/playwright/fixtures.js +24 -0
- package/build/core/playwright/helpers/additionalProfiles.js +25 -0
- package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
- package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
- package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
- package/build/core/playwright/helpers/auth/getUsers.js +118 -0
- package/build/core/playwright/helpers/auth/index.js +76 -0
- package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +54 -0
- package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
- package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
- package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
- package/build/core/playwright/helpers/customFixturesHelper.js +58 -0
- package/build/core/playwright/helpers/fileMutex.js +71 -0
- package/build/core/playwright/helpers/getUserFixtures.js +23 -0
- package/build/core/playwright/helpers/mergeObjects.js +13 -0
- package/build/core/playwright/helpers/parseUserArgs.js +10 -0
- package/build/core/playwright/index.js +10 -89
- package/build/core/playwright/readConfigFile.js +97 -14
- package/build/core/playwright/report-generator.js +9 -10
- package/build/core/playwright/runner/Runner.js +22 -0
- package/build/core/playwright/runner/RunnerHelper.js +43 -0
- package/build/core/playwright/runner/RunnerTypes.js +17 -0
- package/build/core/playwright/runner/SpawnRunner.js +113 -0
- package/build/core/playwright/setup/config-creator.js +101 -90
- package/build/core/playwright/setup/config-utils.js +188 -0
- package/build/core/playwright/setup/custom-reporter.js +136 -0
- package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
- package/build/core/playwright/tagProcessor.js +69 -0
- package/build/core/playwright/test-runner.js +84 -67
- package/build/core/playwright/types.js +44 -0
- package/build/core/playwright/validateFeature.js +28 -0
- package/build/decorators.d.ts +1 -0
- package/build/decorators.js +16 -0
- package/build/index.d.ts +78 -0
- package/build/index.js +73 -5
- package/build/lib/cli.js +38 -5
- package/build/lib/post-install.js +19 -11
- package/build/lint/index.js +3 -6
- package/build/parser/parser.js +205 -0
- package/build/parser/sample.feature +34 -0
- package/build/parser/sample.spec.js +37 -0
- package/build/parser/verifier.js +130 -0
- package/build/setup-folder-structure/helper.js +37 -0
- package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
- package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
- package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
- package/build/setup-folder-structure/samples/actors-index.js +2 -0
- package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
- package/build/setup-folder-structure/samples/editions-index.js +3 -0
- package/build/setup-folder-structure/samples/free-sample.json +25 -0
- package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
- package/build/setup-folder-structure/samples/settings.json +7 -0
- package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
- package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
- package/build/setup-folder-structure/setupProject.js +36 -18
- package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
- package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
- package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
- package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
- package/build/test/core/playwright/helpers/__tests__/additionalProfiles.test.js +45 -0
- package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
- package/build/test/core/playwright/helpers/__tests__/customFixturesHelper.test.js +51 -0
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
- package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
- package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
- package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
- package/build/utils/cliArgsToObject.js +9 -1
- package/build/utils/commonUtils.js +17 -0
- package/build/utils/fileUtils.js +109 -0
- package/build/utils/logger.js +7 -35
- package/build/utils/rootPath.js +16 -9
- package/build/utils/stepDefinitionsFormatter.js +11 -0
- package/changelog.md +136 -10
- package/jest.config.js +29 -11
- package/npm-shrinkwrap.json +10241 -6175
- package/package.json +40 -26
- package/playwright.config.js +5 -55
- package/test-results/.last-run.json +4 -0
- package/unit_reports/unit-report.html +277 -0
- package/build/bdd-framework/cli/commands/env.js +0 -44
- package/build/bdd-framework/cli/commands/export.js +0 -47
- package/build/bdd-framework/cli/commands/test.js +0 -60
- package/build/bdd-framework/cli/index.js +0 -11
- package/build/bdd-framework/cli/options.js +0 -21
- package/build/bdd-framework/cli/worker.js +0 -13
- package/build/bdd-framework/config/dir.js +0 -27
- package/build/bdd-framework/config/env.js +0 -49
- package/build/bdd-framework/config/index.js +0 -92
- package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -45
- package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
- package/build/bdd-framework/cucumber/loadConfig.js +0 -17
- package/build/bdd-framework/cucumber/loadFeatures.js +0 -39
- package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
- package/build/bdd-framework/cucumber/loadSources.js +0 -58
- package/build/bdd-framework/cucumber/loadSteps.js +0 -41
- package/build/bdd-framework/decorators.js +0 -21
- package/build/bdd-framework/gen/formatter.js +0 -92
- package/build/bdd-framework/gen/i18n.js +0 -44
- package/build/bdd-framework/gen/index.js +0 -150
- package/build/bdd-framework/gen/poms.js +0 -47
- package/build/bdd-framework/gen/testFile.js +0 -356
- package/build/bdd-framework/gen/testNode.js +0 -50
- package/build/bdd-framework/index.js +0 -33
- package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -103
- package/build/bdd-framework/playwright/getLocationInFile.js +0 -50
- package/build/bdd-framework/playwright/loadConfig.js +0 -42
- package/build/bdd-framework/playwright/testTypeImpl.js +0 -47
- package/build/bdd-framework/playwright/transform.js +0 -85
- package/build/bdd-framework/playwright/utils.js +0 -24
- package/build/bdd-framework/run/bddFixtures.js +0 -109
- package/build/bdd-framework/run/bddWorld.js +0 -91
- package/build/bdd-framework/snippets/index.js +0 -132
- package/build/bdd-framework/snippets/snippetSyntax.js +0 -50
- package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -32
- package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
- package/build/bdd-framework/stepDefinitions/createBdd.js +0 -52
- package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -110
- package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
- package/build/bdd-framework/utils/index.js +0 -52
- package/build/bdd-framework/utils/jsStringWrap.js +0 -44
- package/build/bdd-framework/utils/logger.js +0 -21
- package/build/setup-folder-structure/env-config-sample.json +0 -17
- package/build/setup-folder-structure/uat-config-sample.js +0 -31
- package/build/setup-folder-structure/user-example.json +0 -3
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {
|
|
2
|
+
expect,
|
|
3
|
+
test,
|
|
4
|
+
createBdd
|
|
5
|
+
} from './core/playwright/index';
|
|
6
|
+
import { fireEvent, render } from '@testing-library/react';
|
|
7
|
+
import {
|
|
8
|
+
PlaywrightTestArgs,
|
|
9
|
+
PlaywrightTestOptions,
|
|
10
|
+
PlaywrightWorkerArgs,
|
|
11
|
+
PlaywrightWorkerOptions,
|
|
12
|
+
TestType,
|
|
13
|
+
Page
|
|
14
|
+
} from '@playwright/test';
|
|
15
|
+
import { DefineStepPattern } from '@cucumber/cucumber/lib/support_code_library_builder/types';
|
|
16
|
+
|
|
17
|
+
export type KeyValue = { [key: string]: any };
|
|
18
|
+
|
|
19
|
+
export type BuiltInFixturesWorker = PlaywrightWorkerArgs &
|
|
20
|
+
PlaywrightWorkerOptions;
|
|
21
|
+
export type BuiltInFixtures = PlaywrightTestArgs &
|
|
22
|
+
PlaywrightTestOptions &
|
|
23
|
+
BuiltInFixturesWorker;
|
|
24
|
+
|
|
25
|
+
export type FixturesArg<T extends KeyValue = {}, W extends KeyValue = {}> = T &
|
|
26
|
+
W &
|
|
27
|
+
BuiltInFixtures;
|
|
28
|
+
|
|
29
|
+
export declare let hasCustomTest: boolean;
|
|
30
|
+
|
|
31
|
+
export declare function createBdd<
|
|
32
|
+
T extends KeyValue = BuiltInFixtures,
|
|
33
|
+
W extends KeyValue = BuiltInFixturesWorker,
|
|
34
|
+
World
|
|
35
|
+
>(
|
|
36
|
+
customTest?: TestType<T, W> | null,
|
|
37
|
+
_CustomWorld?: new (...args: any[]) => World
|
|
38
|
+
): {
|
|
39
|
+
Given: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
40
|
+
When: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
41
|
+
Then: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
42
|
+
And: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
43
|
+
But: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
44
|
+
Step: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
|
|
45
|
+
Before: any;
|
|
46
|
+
After: any;
|
|
47
|
+
BeforeAll: any;
|
|
48
|
+
AfterAll: any;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type StepFunctionFixturesArg<
|
|
52
|
+
T extends KeyValue,
|
|
53
|
+
W extends KeyValue
|
|
54
|
+
> = FixturesArg<T, W>;
|
|
55
|
+
type StepFunction<T extends KeyValue, W extends KeyValue> = (
|
|
56
|
+
fixtures: StepFunctionFixturesArg<T, W>,
|
|
57
|
+
...args: any[]
|
|
58
|
+
) => unknown;
|
|
59
|
+
|
|
60
|
+
const { Given, Then, When, Step, And, But } = createBdd();
|
|
61
|
+
|
|
62
|
+
type UserConfig = import('./core/playwright/readConfigFile').UserConfig;
|
|
63
|
+
|
|
64
|
+
export {
|
|
65
|
+
UserConfig,
|
|
66
|
+
Given,
|
|
67
|
+
Then,
|
|
68
|
+
When,
|
|
69
|
+
Step,
|
|
70
|
+
And,
|
|
71
|
+
But,
|
|
72
|
+
expect,
|
|
73
|
+
test,
|
|
74
|
+
createBdd,
|
|
75
|
+
Page
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export * from '@playwright/test/types/test';
|
package/build/index.js
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.When = exports.Then = exports.Step = exports.Given = exports.But = exports.And = void 0;
|
|
7
|
+
Object.defineProperty(exports, "accountLogin", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _index.accountLogin;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
6
13
|
Object.defineProperty(exports, "createBdd", {
|
|
7
14
|
enumerable: true,
|
|
8
15
|
get: function () {
|
|
@@ -15,16 +22,58 @@ Object.defineProperty(exports, "expect", {
|
|
|
15
22
|
return _index.expect;
|
|
16
23
|
}
|
|
17
24
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
25
|
+
Object.defineProperty(exports, "getDefaultActor", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _index.getDefaultActor;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "getListOfActors", {
|
|
19
32
|
enumerable: true,
|
|
20
33
|
get: function () {
|
|
21
|
-
return
|
|
34
|
+
return _index.getListOfActors;
|
|
22
35
|
}
|
|
23
36
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
37
|
+
Object.defineProperty(exports, "getRunMode", {
|
|
25
38
|
enumerable: true,
|
|
26
39
|
get: function () {
|
|
27
|
-
return
|
|
40
|
+
return _index.getRunMode;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "getUserForSelectedEditionAndProfile", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _index.getUserForSelectedEditionAndProfile;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "isCI", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return _index.isCI;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "isDevelopmentSetup", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return _index.isDevelopmentSetup;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "loadCookiesIfPresent", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _index.loadCookiesIfPresent;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "performLoginSteps", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _index.performLoginSteps;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "setup", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return _index.setup;
|
|
28
77
|
}
|
|
29
78
|
});
|
|
30
79
|
Object.defineProperty(exports, "test", {
|
|
@@ -33,5 +82,24 @@ Object.defineProperty(exports, "test", {
|
|
|
33
82
|
return _index.test;
|
|
34
83
|
}
|
|
35
84
|
});
|
|
85
|
+
Object.defineProperty(exports, "verifyIfCookieFileExists", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return _index.verifyIfCookieFileExists;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
36
91
|
var _index = require("./core/playwright/index");
|
|
37
|
-
|
|
92
|
+
// import { fireEvent, render } from '@testing-library/react';
|
|
93
|
+
|
|
94
|
+
const {
|
|
95
|
+
Given,
|
|
96
|
+
Then,
|
|
97
|
+
When,
|
|
98
|
+
Step
|
|
99
|
+
} = (0, _index.createBdd)();
|
|
100
|
+
exports.Step = Step;
|
|
101
|
+
exports.When = When;
|
|
102
|
+
exports.Then = Then;
|
|
103
|
+
exports.Given = Given;
|
|
104
|
+
const And = exports.And = Then;
|
|
105
|
+
const But = exports.But = Then;
|
package/build/lib/cli.js
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
var _testRunner = _interopRequireDefault(require("../core/playwright/test-runner"));
|
|
5
|
-
var _jestRunner = _interopRequireDefault(require("../core/jest/runner/jest-runner"));
|
|
6
5
|
var _reportGenerator = _interopRequireDefault(require("../core/playwright/report-generator"));
|
|
7
6
|
var _codegen = _interopRequireDefault(require("../core/playwright/codegen"));
|
|
8
7
|
var _logger = require("../utils/logger");
|
|
9
8
|
var _setupProject = _interopRequireDefault(require("../setup-folder-structure/setupProject"));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
var _parser = require("../parser/parser");
|
|
10
|
+
var _clearCaches = _interopRequireDefault(require("../core/playwright/clear-caches"));
|
|
11
|
+
var _helper = _interopRequireDefault(require("../setup-folder-structure/helper"));
|
|
12
|
+
var _parseUserArgs = _interopRequireDefault(require("../core/playwright/helpers/parseUserArgs"));
|
|
13
|
+
var _validateFeature = _interopRequireDefault(require("../core/playwright/validateFeature"));
|
|
14
|
+
// import createJestRunner from '../core/jest/runner/jest-runner';
|
|
15
|
+
|
|
16
|
+
const [,, option, ...otherOptions] = process.argv;
|
|
13
17
|
switch (option) {
|
|
14
18
|
case 'test':
|
|
15
19
|
{
|
|
@@ -18,6 +22,22 @@ switch (option) {
|
|
|
18
22
|
//createJestRunner();
|
|
19
23
|
break;
|
|
20
24
|
}
|
|
25
|
+
case 'validate':
|
|
26
|
+
{
|
|
27
|
+
(0, _validateFeature.default)();
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 're-run-failed':
|
|
31
|
+
{
|
|
32
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Running Failed Tests..');
|
|
33
|
+
let {
|
|
34
|
+
filePath
|
|
35
|
+
} = (0, _parseUserArgs.default)();
|
|
36
|
+
process.env.isRerunFailedCases = true;
|
|
37
|
+
process.env.filePath = filePath;
|
|
38
|
+
(0, _testRunner.default)();
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
21
41
|
case 'report':
|
|
22
42
|
{
|
|
23
43
|
// console.log('\x1b[36mGenerating Reports...\x1b[0m');
|
|
@@ -37,9 +57,22 @@ switch (option) {
|
|
|
37
57
|
(0, _setupProject.default)();
|
|
38
58
|
break;
|
|
39
59
|
}
|
|
60
|
+
case 'generateSpecFile':
|
|
61
|
+
{
|
|
62
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Generating Spec file...');
|
|
63
|
+
(0, _parser.generateSpecCodeForFeatureFile)(otherOptions);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case 'clearCaches':
|
|
67
|
+
{
|
|
68
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Clearing caches...');
|
|
69
|
+
(0, _clearCaches.default)();
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case 'help':
|
|
40
73
|
default:
|
|
41
74
|
{
|
|
42
|
-
|
|
75
|
+
(0, _helper.default)();
|
|
43
76
|
break;
|
|
44
77
|
}
|
|
45
78
|
}
|
|
@@ -4,14 +4,22 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
var _path = _interopRequireDefault(require("path"));
|
|
5
5
|
var _child_process = require("child_process");
|
|
6
6
|
var _logger = require("../utils/logger");
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
var _rootPath = require("../utils/rootPath");
|
|
8
|
+
// We are skipping the download of browsers when NODE_ENV is set to production or flag SKIP_BROWSER_DOWNLOAD is set to true
|
|
9
|
+
|
|
10
|
+
let isSkipDownloadingBrowsers = Boolean(process.env.SKIP_BROWSER_DOWNLOAD);
|
|
11
|
+
let isProductionMode = process.env.NODE_ENV === 'production';
|
|
12
|
+
if (isSkipDownloadingBrowsers || isProductionMode) {
|
|
13
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, 'Skipping browsers download in production mode');
|
|
14
|
+
} else {
|
|
15
|
+
const playwrightPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('playwright'));
|
|
16
|
+
const command = playwrightPath;
|
|
17
|
+
const args = ['install'];
|
|
18
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Downloading browsers for running tests`);
|
|
19
|
+
const childProcess = (0, _child_process.spawn)(command, args, {
|
|
20
|
+
stdio: 'inherit'
|
|
21
|
+
});
|
|
22
|
+
childProcess.on('error', error => {
|
|
23
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, error);
|
|
24
|
+
});
|
|
25
|
+
}
|
package/build/lint/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// const { parse, Document } = require('gherkin-io');
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
Document
|
|
6
|
-
} = require('gherkin-io');
|
|
7
|
-
const document = await parse("Feature: Test\n...", "./features/test.feature");
|
|
3
|
+
// const document = await parse("Feature: Test\n...", "./features/test.feature");
|
|
4
|
+
"use strict";
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.generateSpecCodeForFeatureFile = generateSpecCodeForFeatureFile;
|
|
8
|
+
exports.parseFeature = parseFeature;
|
|
9
|
+
exports.specFileGenerator = specFileGenerator;
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _logger = require("../utils/logger");
|
|
13
|
+
var _cliArgsToObject = require("../utils/cliArgsToObject");
|
|
14
|
+
var _fileUtils = require("../utils/fileUtils");
|
|
15
|
+
var _readConfigFile = require("../core/playwright/readConfigFile");
|
|
16
|
+
var _stepDefinitionsFormatter = require("../utils/stepDefinitionsFormatter");
|
|
17
|
+
function parseFeature(featureContent) {
|
|
18
|
+
const lines = featureContent.split('\n');
|
|
19
|
+
let currentFeature = null;
|
|
20
|
+
let currentScenario = null;
|
|
21
|
+
let insideExampleTable = false;
|
|
22
|
+
let isHeaderRow = false; // To skip the first row in the Examples section
|
|
23
|
+
|
|
24
|
+
const parsedData = {
|
|
25
|
+
feature: null,
|
|
26
|
+
scenarios: []
|
|
27
|
+
};
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
const trimmedLine = line.trim();
|
|
30
|
+
if (trimmedLine.startsWith('Feature:')) {
|
|
31
|
+
if (currentFeature) {
|
|
32
|
+
parsedData.feature = currentFeature;
|
|
33
|
+
}
|
|
34
|
+
currentFeature = {
|
|
35
|
+
name: trimmedLine.replace('Feature:', '').trim(),
|
|
36
|
+
scenarios: []
|
|
37
|
+
};
|
|
38
|
+
} else if (trimmedLine.startsWith('Scenario:')) {
|
|
39
|
+
if (currentScenario) {
|
|
40
|
+
currentFeature.scenarios.push(currentScenario);
|
|
41
|
+
}
|
|
42
|
+
currentScenario = {
|
|
43
|
+
name: trimmedLine.replace('Scenario:', '').trim(),
|
|
44
|
+
steps: [],
|
|
45
|
+
examples: []
|
|
46
|
+
};
|
|
47
|
+
insideExampleTable = false;
|
|
48
|
+
} else if (trimmedLine.startsWith('Examples:')) {
|
|
49
|
+
insideExampleTable = true;
|
|
50
|
+
isHeaderRow = true; // Reset to true for each Examples section
|
|
51
|
+
const headerLine = lines[lines.indexOf(line) + 1].trim();
|
|
52
|
+
const tableHeader = headerLine.split('|').filter(cell => cell !== "").map(cell => cell.trim());
|
|
53
|
+
currentScenario.examples.push({
|
|
54
|
+
tableHeader,
|
|
55
|
+
tableRows: []
|
|
56
|
+
});
|
|
57
|
+
} else if (insideExampleTable && trimmedLine.startsWith('|')) {
|
|
58
|
+
if (!isHeaderRow) {
|
|
59
|
+
const exampleRow = trimmedLine.split('|').filter(cell => cell !== "").map(cell => cell.trim());
|
|
60
|
+
if (exampleRow.length === currentScenario.examples[0].tableHeader.length) {
|
|
61
|
+
currentScenario.examples[0].tableRows.push(exampleRow);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
isHeaderRow = false;
|
|
65
|
+
}
|
|
66
|
+
} else if (trimmedLine.startsWith('Given') || trimmedLine.startsWith('When') || trimmedLine.startsWith('Then') || trimmedLine.startsWith('And')) {
|
|
67
|
+
currentScenario.steps.push(trimmedLine);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (currentFeature) {
|
|
71
|
+
parsedData.feature = currentFeature;
|
|
72
|
+
}
|
|
73
|
+
if (currentScenario) {
|
|
74
|
+
currentFeature.scenarios.push(currentScenario);
|
|
75
|
+
}
|
|
76
|
+
return parsedData;
|
|
77
|
+
}
|
|
78
|
+
function generateSpecFileContent({
|
|
79
|
+
feature
|
|
80
|
+
}) {
|
|
81
|
+
let specContent = 'import { test } from "@zohodesk/testinglibrary";\n\n';
|
|
82
|
+
if (feature && feature.scenarios && feature.scenarios.length > 0) {
|
|
83
|
+
//specContent += `test.describe('${feature.name}', () => {\n`;
|
|
84
|
+
specContent += `// Feature: ${feature.name} \n`;
|
|
85
|
+
feature.scenarios.forEach(scenario => {
|
|
86
|
+
// specContent += ' /*\n'
|
|
87
|
+
// if (scenario.steps && scenario.steps.length > 0) {
|
|
88
|
+
// scenario.steps.forEach(step => {
|
|
89
|
+
// specContent += ` ** ${step}\n`
|
|
90
|
+
// })
|
|
91
|
+
|
|
92
|
+
// }
|
|
93
|
+
// specContent += ' */\n'
|
|
94
|
+
specContent += `test('${scenario.name}', async({ Given, When, Then, And }) => {\n`;
|
|
95
|
+
//specContent += ` // Your implementation here\n`;
|
|
96
|
+
if (scenario.steps && scenario.steps.length > 0) {
|
|
97
|
+
scenario.steps.forEach(step => {
|
|
98
|
+
let foundDelimiter = (0, _stepDefinitionsFormatter.findDelimiterFromStep)(step);
|
|
99
|
+
if (foundDelimiter) {
|
|
100
|
+
// Wrap the part of the string after the delimiter with a function call
|
|
101
|
+
let splitResult = step.split(foundDelimiter);
|
|
102
|
+
let wrappedString = ` await ${foundDelimiter}(${JSON.stringify(splitResult[1].trim())}, () => {\n //${foundDelimiter} Implementation will be here\n })();\n\n`;
|
|
103
|
+
specContent += wrappedString;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
specContent += `});\n\n`;
|
|
108
|
+
});
|
|
109
|
+
//specContent += `});\n\n`;
|
|
110
|
+
}
|
|
111
|
+
return specContent;
|
|
112
|
+
}
|
|
113
|
+
function updateExistingSpecFile({
|
|
114
|
+
feature
|
|
115
|
+
}, specFile) {
|
|
116
|
+
if (feature && feature.scenarios && feature.scenarios.length > 0) {
|
|
117
|
+
let specFileCode = _fs.default.readFileSync(specFile, 'utf8');
|
|
118
|
+
feature.scenarios.forEach(({
|
|
119
|
+
name,
|
|
120
|
+
steps
|
|
121
|
+
}) => {
|
|
122
|
+
const scenarioComment = `/*\n${steps.map(step => ` ** ${step}`).join('\n')}\n */`;
|
|
123
|
+
const testNamePattern = new RegExp(`test\\('${name}',`, 'g');
|
|
124
|
+
const testNameMatches = specFileCode.match(testNamePattern);
|
|
125
|
+
if (testNameMatches) {
|
|
126
|
+
testNameMatches.forEach(match => {
|
|
127
|
+
const startIdx = specFileCode.indexOf(match);
|
|
128
|
+
|
|
129
|
+
// Find the index of the comment above the test block
|
|
130
|
+
const commentStartIdx = specFileCode.lastIndexOf('/*', startIdx);
|
|
131
|
+
const commentEndIdx = specFileCode.lastIndexOf('*/', startIdx);
|
|
132
|
+
if (commentStartIdx >= 0 && commentEndIdx > commentStartIdx) {
|
|
133
|
+
// Remove the old comment above the test block
|
|
134
|
+
specFileCode = specFileCode.slice(0, commentStartIdx) + scenarioComment + specFileCode.slice(commentEndIdx + 2);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
} else {
|
|
138
|
+
// Create a new test block if the test name is not found
|
|
139
|
+
const newTestBlock = ` ${scenarioComment}\n test('${name}', () => {\n // Your implementation here\n });\n\n\n`;
|
|
140
|
+
// Locate the closest describe block for the new test
|
|
141
|
+
const lastDescribeEndIdx = specFileCode.lastIndexOf('});');
|
|
142
|
+
specFileCode = specFileCode.slice(0, lastDescribeEndIdx) + newTestBlock + specFileCode.slice(lastDescribeEndIdx);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Save the updated code back to the spec file
|
|
147
|
+
_fs.default.writeFileSync(specFile, specFileCode, 'utf8');
|
|
148
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Spec file updated successfully');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function specFileGenerator(filePath, isUpdate) {
|
|
152
|
+
_logger.Logger.log(_logger.Logger.INFO_TYPE, `Generating spec file using file ${filePath}`);
|
|
153
|
+
// Read the Gherkin feature file
|
|
154
|
+
let {
|
|
155
|
+
featureFilesFolder = 'feature-files',
|
|
156
|
+
stepDefinitionsFolder = 'steps'
|
|
157
|
+
} = (0, _readConfigFile.generateConfigFromFile)();
|
|
158
|
+
_fs.default.readFile(filePath, 'utf8', (err, data) => {
|
|
159
|
+
if (err) {
|
|
160
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Error reading the file: ${err}`);
|
|
161
|
+
} else {
|
|
162
|
+
// Parse the feature file content and get the JSON-like object
|
|
163
|
+
const parsedFeature = parseFeature(data);
|
|
164
|
+
let specFilePath = filePath.replace(/\.feature$/, '.spec.js');
|
|
165
|
+
if (filePath.includes(`${featureFilesFolder}`)) {
|
|
166
|
+
specFilePath = specFilePath.replace(`/${featureFilesFolder}/`, `/${stepDefinitionsFolder}/`);
|
|
167
|
+
} else {
|
|
168
|
+
specFilePath = specFilePath.replace('./', `${stepDefinitionsFolder}`);
|
|
169
|
+
}
|
|
170
|
+
if ((0, _fileUtils.checkIfFileExists)(specFilePath)) {
|
|
171
|
+
if (isUpdate) {
|
|
172
|
+
updateExistingSpecFile(parsedFeature, specFilePath);
|
|
173
|
+
} else {
|
|
174
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'File Already exists. Make sure to either delete or pass --update option true');
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Output the JSON-like object
|
|
180
|
+
//console.log(JSON.stringify(parsedFeature, null, 2));
|
|
181
|
+
//fs.writeFileSync('./sample.json', JSON.stringify(parsedFeature, null, 2));
|
|
182
|
+
const specFileContent = generateSpecFileContent(parsedFeature);
|
|
183
|
+
|
|
184
|
+
// Write the spec file content to a new file
|
|
185
|
+
try {
|
|
186
|
+
(0, _fileUtils.writeFileContents)(specFilePath, specFileContent);
|
|
187
|
+
_logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Spec file generated successfully.');
|
|
188
|
+
} catch (writeErr) {
|
|
189
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Error writing the spec file: ${writeErr}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
function generateSpecCodeForFeatureFile(options) {
|
|
195
|
+
let cliObj = (0, _cliArgsToObject.cliArgsToObject)(options);
|
|
196
|
+
let {
|
|
197
|
+
featureFile: featureFilePath = null,
|
|
198
|
+
update = false
|
|
199
|
+
} = cliObj;
|
|
200
|
+
if (featureFilePath) {
|
|
201
|
+
specFileGenerator(_path.default.join(process.cwd(), './', featureFilePath), update);
|
|
202
|
+
} else {
|
|
203
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Need option --featureFile to run this command');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Feature: Home Page
|
|
2
|
+
|
|
3
|
+
Scenario: Home Page Default content
|
|
4
|
+
Given user is on "<App>" home page
|
|
5
|
+
Then user gets a "<App>" bootcamp section
|
|
6
|
+
And username is also displayed on right corner
|
|
7
|
+
|
|
8
|
+
Examples:
|
|
9
|
+
| App |
|
|
10
|
+
| GitHub |
|
|
11
|
+
|
|
12
|
+
Scenario: GitHub Bootcamp Section
|
|
13
|
+
Given user is on "<Site>" home page
|
|
14
|
+
When user focuses on "<Site>" Bootcamp Section
|
|
15
|
+
Then user gets an option to setup git
|
|
16
|
+
And user gets an option to create repository
|
|
17
|
+
And user gets an option to Fork Repository
|
|
18
|
+
And user gets an option to work together
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
| Site |
|
|
22
|
+
| GitHub |
|
|
23
|
+
|
|
24
|
+
Scenario: Top Banner content
|
|
25
|
+
Given user is on "<Product>" home page
|
|
26
|
+
When user focuses on Top Banner
|
|
27
|
+
Then user gets an option of home page
|
|
28
|
+
And user gets an option to search
|
|
29
|
+
And user gets settings options
|
|
30
|
+
And user gets an option to logout
|
|
31
|
+
|
|
32
|
+
Examples:
|
|
33
|
+
| Product |
|
|
34
|
+
| GitHub |
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _testinglibrary = require("@zohodesk/testinglibrary");
|
|
4
|
+
_testinglibrary.test.describe('Home Page', () => {
|
|
5
|
+
/*
|
|
6
|
+
** Given user is on "<App>" home page
|
|
7
|
+
** Then user gets a "<App>" bootcamp section
|
|
8
|
+
** And username is also displayed on right corner
|
|
9
|
+
*/
|
|
10
|
+
(0, _testinglibrary.test)('Home Page Default content', () => {
|
|
11
|
+
// Your implementation here
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
** Given user is on "<Site>" home page
|
|
16
|
+
** When user focuses on "<Site>" Bootcamp Section
|
|
17
|
+
** Then user gets an option to setup git
|
|
18
|
+
** And user gets an option to create repository
|
|
19
|
+
** And user gets an option to Fork Repository
|
|
20
|
+
** And user gets an option to work together
|
|
21
|
+
*/
|
|
22
|
+
(0, _testinglibrary.test)('GitHub Bootcamp Section', () => {
|
|
23
|
+
// Your implementation here
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
** Given user is on "<Product>" home page
|
|
28
|
+
** When user focuses on Top Banner
|
|
29
|
+
** Then user gets an option of home page
|
|
30
|
+
** And user gets an option to search
|
|
31
|
+
** And user gets settings options
|
|
32
|
+
** And user gets an option to logout
|
|
33
|
+
*/
|
|
34
|
+
(0, _testinglibrary.test)('Top Banner content', () => {
|
|
35
|
+
// Your implementation here
|
|
36
|
+
});
|
|
37
|
+
});
|