@zohodesk/testinglibrary 0.0.3 → 0.0.4-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.
Files changed (130) hide show
  1. package/.babelrc +24 -0
  2. package/.eslintrc.js +31 -0
  3. package/.gitlab-ci.yml +175 -0
  4. package/.prettierrc +6 -0
  5. package/README.md +151 -1
  6. package/bin/cli.js +1 -1
  7. package/bin/postinstall.js +1 -16
  8. package/build/common/data-generator/steps/DataGenerator.spec.js +19 -0
  9. package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +19 -0
  10. package/build/common/multi-actor/steps/multiActorHandling.spec.js +26 -0
  11. package/build/common/searchFake/helpers/rpcRequestHelper.js +41 -0
  12. package/build/common/searchFake/steps/searchFake.spec.js +26 -0
  13. package/build/core/dataGenerator/DataGenerator.js +94 -0
  14. package/build/core/dataGenerator/DataGeneratorHelper.js +49 -0
  15. package/{src → build}/core/jest/preprocessor/jsPreprocessor.js +4 -6
  16. package/{src → build}/core/jest/runner/jest-runner.js +17 -15
  17. package/build/core/jest/setup/index.js +3 -0
  18. package/build/core/playwright/builtInFixtures/actorContext.js +75 -0
  19. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  20. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  21. package/build/core/playwright/builtInFixtures/context.js +32 -0
  22. package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
  23. package/build/core/playwright/builtInFixtures/i18N.js +41 -0
  24. package/build/core/playwright/builtInFixtures/index.js +46 -0
  25. package/build/core/playwright/builtInFixtures/page.js +38 -0
  26. package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
  27. package/build/core/playwright/clear-caches.js +49 -0
  28. package/build/core/playwright/codegen.js +55 -0
  29. package/build/core/playwright/configuration/Configuration.js +25 -0
  30. package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
  31. package/build/core/playwright/configuration/UserArgs.js +12 -0
  32. package/build/core/playwright/constants/browserTypes.js +12 -0
  33. package/build/core/playwright/constants/fileMutexConfig.js +9 -0
  34. package/build/core/playwright/custom-commands.js +7 -0
  35. package/build/core/playwright/env-initializer.js +43 -0
  36. package/build/core/playwright/fixtures.js +24 -0
  37. package/build/core/playwright/helpers/additionalProfiles.js +25 -0
  38. package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
  39. package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
  40. package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
  41. package/build/core/playwright/helpers/auth/getUsers.js +118 -0
  42. package/build/core/playwright/helpers/auth/index.js +76 -0
  43. package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +54 -0
  44. package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
  45. package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
  46. package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
  47. package/build/core/playwright/helpers/customFixturesHelper.js +58 -0
  48. package/build/core/playwright/helpers/fileMutex.js +71 -0
  49. package/build/core/playwright/helpers/getUserFixtures.js +23 -0
  50. package/build/core/playwright/helpers/mergeObjects.js +13 -0
  51. package/build/core/playwright/helpers/parseUserArgs.js +10 -0
  52. package/build/core/playwright/index.js +24 -0
  53. package/build/core/playwright/readConfigFile.js +147 -0
  54. package/build/core/playwright/report-generator.js +42 -0
  55. package/build/core/playwright/runner/Runner.js +22 -0
  56. package/build/core/playwright/runner/RunnerHelper.js +43 -0
  57. package/build/core/playwright/runner/RunnerTypes.js +17 -0
  58. package/build/core/playwright/runner/SpawnRunner.js +113 -0
  59. package/build/core/playwright/setup/config-creator.js +117 -0
  60. package/build/core/playwright/setup/config-utils.js +188 -0
  61. package/build/core/playwright/setup/custom-reporter.js +136 -0
  62. package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
  63. package/build/core/playwright/tagProcessor.js +69 -0
  64. package/build/core/playwright/test-runner.js +116 -0
  65. package/build/core/playwright/types.js +44 -0
  66. package/build/core/playwright/validateFeature.js +28 -0
  67. package/build/decorators.d.ts +1 -0
  68. package/build/decorators.js +16 -0
  69. package/build/index.d.ts +78 -0
  70. package/build/index.js +105 -0
  71. package/build/lib/cli.js +78 -0
  72. package/build/lib/post-install.js +25 -0
  73. package/build/lint/index.js +4 -0
  74. package/build/parser/parser.js +205 -0
  75. package/build/parser/sample.feature +34 -0
  76. package/build/parser/sample.spec.js +37 -0
  77. package/build/parser/verifier.js +130 -0
  78. package/build/setup-folder-structure/helper.js +37 -0
  79. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  80. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  81. package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
  82. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  83. package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
  84. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  85. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  86. package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
  87. package/build/setup-folder-structure/samples/settings.json +7 -0
  88. package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
  89. package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
  90. package/build/setup-folder-structure/setupProject.js +122 -0
  91. package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
  92. package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
  93. package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
  94. package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
  95. package/build/test/core/playwright/helpers/__tests__/additionalProfiles.test.js +45 -0
  96. package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
  97. package/build/test/core/playwright/helpers/__tests__/customFixturesHelper.test.js +51 -0
  98. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
  99. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
  100. package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
  101. package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
  102. package/build/utils/cliArgsToObject.js +72 -0
  103. package/build/utils/commonUtils.js +17 -0
  104. package/build/utils/fileUtils.js +109 -0
  105. package/build/utils/getFilePath.js +11 -0
  106. package/build/utils/logger.js +28 -0
  107. package/build/utils/rootPath.js +53 -0
  108. package/build/utils/stepDefinitionsFormatter.js +11 -0
  109. package/changelog.md +153 -1
  110. package/jest.config.js +29 -11
  111. package/npm-shrinkwrap.json +10902 -4825
  112. package/package.json +47 -17
  113. package/playwright.config.js +6 -56
  114. package/test-results/.last-run.json +4 -0
  115. package/unit_reports/unit-report.html +260 -0
  116. package/src/core/jest/setup/index.js +0 -165
  117. package/src/core/playwright/codegen.js +0 -60
  118. package/src/core/playwright/custom-commands.js +0 -3
  119. package/src/core/playwright/env-initializer.js +0 -24
  120. package/src/core/playwright/index.js +0 -82
  121. package/src/core/playwright/readConfigFile.js +0 -30
  122. package/src/core/playwright/report-generator.js +0 -43
  123. package/src/core/playwright/setup/config-creator.js +0 -79
  124. package/src/core/playwright/test-runner.js +0 -64
  125. package/src/index.js +0 -9
  126. package/src/lib/cli.js +0 -35
  127. package/src/utils/cliArgsToObject.js +0 -35
  128. package/src/utils/getFilePath.js +0 -9
  129. package/src/utils/logger.js +0 -28
  130. package/src/utils/rootPath.js +0 -51
@@ -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
+ });
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _path = _interopRequireDefault(require("path"));
5
+ var _fastGlob = _interopRequireDefault(require("fast-glob"));
6
+ var _parser = require("./parser");
7
+ var _logger = require("../utils/logger");
8
+ var _fileUtils = require("../utils/fileUtils");
9
+ var _readConfigFile = require("../core/playwright/readConfigFile");
10
+ var _stepDefinitionsFormatter = require("../utils/stepDefinitionsFormatter");
11
+ // Specify the directory where you want to search for .feature and .spec.js files
12
+ const directoryPath = './uat';
13
+
14
+ // Use glob to match .feature files in the directory
15
+ const featurePattern = _path.default.join(process.cwd(), directoryPath, '**/*.feature');
16
+
17
+ // function onSpecFileNotFound() { }
18
+
19
+ function verifyIfMultipleStepsExists(steps) {
20
+ let isMultipleStepsFound = false;
21
+ Object.keys(steps).map(step => {
22
+ if (steps[step].length > 1) {
23
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Multiple Steps Found for ${step} \n`);
24
+ steps[step].forEach(fileName => {
25
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Files: \n ${fileName} \n`);
26
+ });
27
+ // multipleSteps.push({ step: steps[step] });
28
+ isMultipleStepsFound = true;
29
+ }
30
+ });
31
+ return isMultipleStepsFound;
32
+ }
33
+ function extractExamplesToSeperateFile(examples, scenarioIndex, filePath, featureName) {
34
+ let exampleFileContent = `export const ${featureName.toUpperCase()}_SCENARIO_${scenarioIndex} = ${JSON.stringify(examples, null, 2)};\r\n`;
35
+ const cleanedData = exampleFileContent.replace(/\r\n/g, '\n');
36
+ try {
37
+ (0, _fileUtils.writeFileContents)(filePath, cleanedData, {
38
+ flag: 'a'
39
+ });
40
+ } catch (err) {
41
+ _logger.Logger.error(err);
42
+ throw new Error(`Error appending or creating the test data file: ${filePath}`);
43
+ }
44
+ }
45
+ function verifyFeatureFileWithSpecFile() {
46
+ try {
47
+ let errorCount = 0;
48
+ let allStepsFound = {};
49
+ let {
50
+ featureFilesFolder = 'feature-files',
51
+ stepDefinitionsFolder = 'steps'
52
+ } = (0, _readConfigFile.generateConfigFromFile)();
53
+ const featureFiles = _fastGlob.default.globSync([featurePattern], {
54
+ dot: true
55
+ });
56
+ featureFiles.forEach(featureFile => {
57
+ // Construct the corresponding .spec.js filename
58
+ const specFile = featureFile.replace(/\.feature$/, '.spec.js').replace(`/${featureFilesFolder}/`, `/${stepDefinitionsFolder}/`);
59
+ let featureFileNameExtract = featureFile.split('/').pop();
60
+ let featurePrefixName = featureFileNameExtract.split('.')[0];
61
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `parsing feature file ${featureFileNameExtract}...`);
62
+ // Check if the .spec.js file exists
63
+
64
+ if ((0, _fileUtils.checkIfFileExists)(specFile)) {
65
+ let featureContents = (0, _fileUtils.readFileContents)(featureFile);
66
+ let specContents = (0, _fileUtils.readFileContents)(specFile);
67
+ //let [featureContents, specContents] = Promise.all([readFileContents(featureFile), readFileContents(specFile)]);
68
+ if (featureContents !== null && specContents !== null) {
69
+ const featureJSON = (0, _parser.parseFeature)(featureContents);
70
+ if (featureJSON && featureJSON.feature) {
71
+ let featureName = featureJSON.feature.name;
72
+ if (specContents.includes(featureName)) {
73
+ const scenarios = featureJSON.feature.scenarios;
74
+ const specLines = specContents.split('\n'); // Split specContents into lines
75
+ let testDataFilePath = featureFile.replace(`/${featureFilesFolder}/`, '/test-data/').replace(/\.feature$/, '.data.js');
76
+ // Examples to test data conversion. we are deleting the existing test data file and create a new file.
77
+ (0, _fileUtils.deleteFile)(testDataFilePath);
78
+ for (let i = 0; i < scenarios.length; i++) {
79
+ let scenario = scenarios[i];
80
+ const scenarioName = scenario.name;
81
+ const scenarioExamples = scenario.examples;
82
+ extractExamplesToSeperateFile(scenarioExamples, i, testDataFilePath, featurePrefixName);
83
+
84
+ // spec file check
85
+ if (!specLines.some(line => line.includes(scenarioName))) {
86
+ errorCount++;
87
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Scenario: ${scenarioName} is missing in spec file`);
88
+ }
89
+ for (const step of scenario.steps) {
90
+ if (!allStepsFound[step]) {
91
+ allStepsFound[step] = [specFile];
92
+ } else {
93
+ allStepsFound[step].push(specFile);
94
+ }
95
+ const foundDelimiter = (0, _stepDefinitionsFormatter.findDelimiterFromStep)(step);
96
+ if (foundDelimiter) {
97
+ let splitResult = step.split(foundDelimiter);
98
+ if (!specLines.some(line => line.includes(splitResult[1].trim().replace(/"/g, '\\"')))) {
99
+ errorCount++;
100
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Scenario: ${scenarioName} \n Step: ${step} is missing in the spec file ${specFile}`);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ } else {
106
+ errorCount++;
107
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `Feature Name ${featureName} does not match/exist in ${specFile}`);
108
+ }
109
+ }
110
+ } else {
111
+ errorCount++;
112
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Error while reading feature file ${featureFile} or spec file ${specFile}`);
113
+ }
114
+ } else {
115
+ errorCount++;
116
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `No corresponding .spec.js file found for ${featureFile}`);
117
+ }
118
+ });
119
+ // Multiple steps found warning
120
+ verifyIfMultipleStepsExists(allStepsFound);
121
+ if (errorCount > 0) {
122
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Total Number of Errors found - ${errorCount}`);
123
+ throw new Error('Error while parsing feature files. Please fix the above issues before running test cases');
124
+ }
125
+ } catch (err) {
126
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, err);
127
+ process.exit(1);
128
+ }
129
+ }
130
+ verifyFeatureFileWithSpecFile();
@@ -0,0 +1,37 @@
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('re-run-failed').description('This command will re-run the failed test cases based on test summary');
28
+ _commander.program.command('codegen').description('This command is used to assist developer to write test case');
29
+ _commander.program.option('--headed', 'Run tests with a headed browser.');
30
+ _commander.program.option('--debug', 'This command is used to initiate a debugging session');
31
+ _commander.program.option('--tags', 'Run specific test case with mentioned tags (Usage: -- --tags="@live")');
32
+ _commander.program.option('--workers', 'Specify number of workers to run the test case parallely (Usage: -- --workers=2)');
33
+ _commander.program.option('--edition', 'Specify edition to run the test cases (Usage: -- --edition="standard". This will run the test cases with either no edition mentioned or edition standard)');
34
+ _commander.program.option('--browsers', 'Specify the browsers on which the test case should run (Usage: -- --browsers="chrome,firefox,safari")');
35
+ _commander.program.parse(process.argv);
36
+ }
37
+ var _default = exports.default = helpercmd;
@@ -0,0 +1,25 @@
1
+ <script>
2
+ function sortEdition(event) {
3
+ var currentURL = window.location.href;
4
+ const endPointCount = window.location.href.indexOf('#');
5
+ if (!(endPointCount == -1)) {
6
+ window.history.pushState({}, '', currentURL.slice(0, endPointCount));
7
+ currentURL = currentURL.slice(0, endPointCount);
8
+ }
9
+ console.log(currentURL);
10
+ window.open(`${currentURL}#?q=@edition_${event.target.value}`, '_self');
11
+ }
12
+ </script>
13
+ <div class="mainContainer" style="margin-left: 20px; display: flex;">
14
+ <div class="selectEditionContainer" style="padding: 20px;">
15
+ <select class="selectEdition" style="padding: 5px; width: 100px; border-radius: 6px; border: 1px solid var(--color-border-default);" onchange="sortEdition(event)">
16
+ <option value="EnterPrise">EnterPrise</option>
17
+ <option value="Professional">Professional</option>
18
+ <option value="Express">Express</option>
19
+ <option value="Standard">Standard</option>
20
+ <option value="Free">Free</option>
21
+ </select>
22
+ </div>
23
+ </div>
24
+
25
+
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.preProcessReport = preProcessReport;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _logger = require("./../../utils/logger");
10
+ var _path = _interopRequireDefault(require("path"));
11
+ const htmlFilePath = _path.default.resolve(process.cwd(), 'uat', 'playwright-report', 'index.html');
12
+ const fileHtml = _fs.default.readFileSync(htmlFilePath, 'utf-8');
13
+ const addOnHtml = _fs.default.readFileSync(_path.default.resolve(__filename, '../', 'addonScript.html'), 'utf-8');
14
+ const splitedHTML = fileHtml.split('\n');
15
+ const toAdd = addOnHtml.split('\n');
16
+ function preProcessReport() {
17
+ if (_fs.default.existsSync(htmlFilePath)) {
18
+ const modifiedContent = [...splitedHTML.slice(0, 55), ...toAdd, ...splitedHTML.slice(56)].join('').toString();
19
+ _fs.default.writeFileSync(htmlFilePath, modifiedContent);
20
+ return;
21
+ } else {
22
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Report is not generated Properly ...');
23
+ }
24
+ return null;
25
+ }
@@ -0,0 +1,19 @@
1
+ // This is the sample file generated by testing framework. You can change as per the respective project login
2
+
3
+ const getUrlOrigin = require('../shared/url-helpers/getUrlOrigin');
4
+
5
+ async function accountLogin( { page, email, password } ) {
6
+ await page.locator('#login_id').fill(email);
7
+ await page.locator('#nextbtn').click();
8
+ await page.locator('#password').fill(password);
9
+ await page.locator('#nextbtn').click();
10
+
11
+ const domainUrlOrigin = getUrlOrigin(process.env.domain);
12
+ await page.waitForNavigation();
13
+ await Promise.race([
14
+ page.waitForURL(`${domainUrlOrigin}/**`),
15
+ page.waitForURL('**/announcement/**')
16
+ ]);
17
+ }
18
+
19
+ module.exports = accountLogin;
@@ -0,0 +1,2 @@
1
+ const editions = require('./editions/index');
2
+ module.exports = { editions }
@@ -0,0 +1,15 @@
1
+ /* eslint-disable no-console */
2
+ import { test as setup, expect } from '@zohodesk/testinglibrary';
3
+ import {
4
+ performLoginSteps,
5
+ getDefaultActor
6
+ } from '@zohodesk/testinglibrary/helpers';
7
+
8
+ import { loginSteps , validateLogin } from './testSetup';
9
+
10
+ const user = getDefaultActor();
11
+
12
+ setup(`${user.edition} - Authentication`, async ({ page }) => {
13
+ //Implement performLoginSteps here
14
+ await performLoginSteps({page, ...user},validateLogin ,loginSteps);
15
+ });
@@ -0,0 +1,3 @@
1
+ const free = require('./free.json');
2
+ const editions = { free};
3
+ module.exports = editions;
@@ -0,0 +1,25 @@
1
+ [
2
+ {
3
+ "id": "1",
4
+ "edition": "free",
5
+ "orgName": "orgFree",
6
+ "profiles": [
7
+ {
8
+ "profile": "admin",
9
+ "email": "admin+free@zohotest.com",
10
+ "password": "password@0987"
11
+ },
12
+ {
13
+ "profile": "agent",
14
+ "email": "agent@zohotest.com",
15
+ "password": "password@12345"
16
+ },
17
+ {
18
+ "profile": "lightagent",
19
+ "email": "lightagent@zohotest.com",
20
+ "password": "password@12345"
21
+ }
22
+ ]
23
+ }
24
+ ]
25
+
@@ -0,0 +1,37 @@
1
+ import { existsSync, readFileSync, writeFileSync } from 'fs';
2
+ import path from 'path';
3
+ import { Logger } from '../utils/logger';
4
+ import { generateConfigFromFile } from '../core/playwright/readConfigFile';
5
+ const gitIgnoreAbsolutePath = path.resolve(process.cwd(), '../', '../')
6
+
7
+ const { reportPath = path.resolve(process.cwd(), 'uat', 'playwright-reports') } = generateConfigFromFile();
8
+ const testResultsPath = path.resolve(process.cwd(), 'uat', 'test-results');
9
+
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)
16
+
17
+ const dirpathtoIgnore = `${testResultsRelativepath}\n${reportRelativepath}\n${featuregenRelativePath}`
18
+
19
+ function updateGitIgnore() {
20
+ if (existsSync(path.resolve(process.cwd(), '../', '../', '.gitignore'))) {
21
+ let gitIgnoreData = readFileSync(path.resolve(process.cwd(), '../', '../', '.gitignore'), 'utf-8', (err) => {
22
+ if (err) {
23
+ Logger.log(Logger.FAILURE_TYPE, 'cannot able to read git ignore ')
24
+ // process.exit()
25
+ }
26
+ })
27
+ if (gitIgnoreData.includes(dirpathtoIgnore)) {
28
+ return
29
+ } else {
30
+ writeFileSync(path.resolve(process.cwd(), '../', '../', '.gitignore', dirpathtoIgnore, null, 2))
31
+ }
32
+ } else {
33
+ Logger.log(Logger.INFO_TYPE, 'GitIgnore file is No Found ....')
34
+ }
35
+ }
36
+
37
+ export default updateGitIgnore;
@@ -0,0 +1,7 @@
1
+ {
2
+ "environment": "dev",
3
+ "edition": "enterprise",
4
+ "profile": "admin",
5
+ "domain": "https://zdesk-devops25.csez.zohocorpin.com:31037/agent",
6
+ "devUrl" : ""
7
+ }
@@ -0,0 +1,14 @@
1
+ /* eslint-disable global-require */
2
+ const accountLogin = require('./accountLogin');
3
+
4
+ async function verifyPageIsLoaded({page}) {
5
+
6
+ //Implement your validation logic here
7
+ //Refer deskclientapp testSetup.js
8
+ }
9
+
10
+ module.exports = {
11
+ loginSteps:accountLogin,
12
+ validateLogin:verifyPageIsLoaded,
13
+ page:()=>{}
14
+ };