@zohodesk/testinglibrary 0.0.1 → 0.0.2-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 (114) hide show
  1. package/.babelrc +23 -0
  2. package/.eslintrc.js +31 -0
  3. package/.gitlab-ci.yml +163 -0
  4. package/.prettierrc +6 -0
  5. package/README.md +98 -18
  6. package/bin/cli.js +2 -2
  7. package/bin/postinstall.js +1 -16
  8. package/{src → build}/core/jest/preprocessor/jsPreprocessor.js +7 -9
  9. package/{src → build}/core/jest/runner/jest-runner.js +46 -45
  10. package/build/core/jest/setup/index.js +3 -0
  11. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  12. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  13. package/build/core/playwright/builtInFixtures/context.js +32 -0
  14. package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
  15. package/build/core/playwright/builtInFixtures/i18N.js +41 -0
  16. package/build/core/playwright/builtInFixtures/index.js +44 -0
  17. package/build/core/playwright/builtInFixtures/page.js +101 -0
  18. package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
  19. package/build/core/playwright/clear-caches.js +49 -0
  20. package/build/core/playwright/codegen.js +55 -0
  21. package/build/core/playwright/configuration/Configuration.js +25 -0
  22. package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
  23. package/build/core/playwright/configuration/UserArgs.js +12 -0
  24. package/build/core/playwright/constants/browserTypes.js +12 -0
  25. package/build/core/playwright/constants/fileMutexConfig.js +9 -0
  26. package/build/core/playwright/custom-commands.js +7 -0
  27. package/build/core/playwright/env-initializer.js +43 -0
  28. package/build/core/playwright/fixtures.js +24 -0
  29. package/build/core/playwright/helpers/additionalProfiles.js +18 -0
  30. package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
  31. package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
  32. package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
  33. package/build/core/playwright/helpers/auth/getUsers.js +118 -0
  34. package/build/core/playwright/helpers/auth/index.js +76 -0
  35. package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
  36. package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
  37. package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
  38. package/build/core/playwright/helpers/fileMutex.js +71 -0
  39. package/build/core/playwright/helpers/getUserFixtures.js +23 -0
  40. package/build/core/playwright/helpers/mergeObjects.js +13 -0
  41. package/build/core/playwright/helpers/parseUserArgs.js +10 -0
  42. package/build/core/playwright/index.js +24 -0
  43. package/build/core/playwright/readConfigFile.js +147 -0
  44. package/build/core/playwright/report-generator.js +42 -0
  45. package/build/core/playwright/runner/Runner.js +22 -0
  46. package/build/core/playwright/runner/RunnerHelper.js +43 -0
  47. package/build/core/playwright/runner/RunnerTypes.js +17 -0
  48. package/build/core/playwright/runner/SpawnRunner.js +110 -0
  49. package/build/core/playwright/setup/config-creator.js +113 -0
  50. package/build/core/playwright/setup/config-utils.js +189 -0
  51. package/build/core/playwright/setup/custom-reporter.js +136 -0
  52. package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
  53. package/build/core/playwright/tagProcessor.js +69 -0
  54. package/build/core/playwright/test-runner.js +116 -0
  55. package/build/core/playwright/types.js +44 -0
  56. package/build/core/playwright/validateFeature.js +28 -0
  57. package/build/decorators.d.ts +1 -0
  58. package/build/decorators.js +16 -0
  59. package/build/index.d.ts +78 -0
  60. package/build/index.js +105 -0
  61. package/build/lib/cli.js +78 -0
  62. package/build/lib/post-install.js +25 -0
  63. package/build/lint/index.js +4 -0
  64. package/build/parser/parser.js +205 -0
  65. package/build/parser/sample.feature +34 -0
  66. package/build/parser/sample.spec.js +37 -0
  67. package/build/parser/verifier.js +130 -0
  68. package/build/setup-folder-structure/helper.js +37 -0
  69. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  70. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  71. package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
  72. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  73. package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
  74. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  75. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  76. package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
  77. package/build/setup-folder-structure/samples/settings.json +7 -0
  78. package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
  79. package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
  80. package/build/setup-folder-structure/setupProject.js +122 -0
  81. package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
  82. package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
  83. package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
  84. package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
  85. package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
  86. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
  87. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
  88. package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
  89. package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
  90. package/build/utils/cliArgsToObject.js +72 -0
  91. package/build/utils/fileUtils.js +89 -0
  92. package/build/utils/getFilePath.js +11 -0
  93. package/build/utils/logger.js +57 -0
  94. package/build/utils/rootPath.js +53 -0
  95. package/build/utils/stepDefinitionsFormatter.js +11 -0
  96. package/changelog.md +167 -0
  97. package/jest.config.js +81 -63
  98. package/npm-shrinkwrap.json +12575 -0
  99. package/package.json +60 -31
  100. package/playwright.config.js +62 -112
  101. package/src/core/jest/setup/index.js +0 -165
  102. package/src/core/playwright/codegen.js +0 -61
  103. package/src/core/playwright/custom-commands.js +0 -3
  104. package/src/core/playwright/env-initializer.js +0 -24
  105. package/src/core/playwright/index.js +0 -81
  106. package/src/core/playwright/readConfigFile.js +0 -18
  107. package/src/core/playwright/report-generator.js +0 -44
  108. package/src/core/playwright/test-runner.js +0 -64
  109. package/src/index.js +0 -9
  110. package/src/lib/cli.js +0 -35
  111. package/src/utils/cliArgsToObject.js +0 -35
  112. package/src/utils/getFilePath.js +0 -9
  113. package/src/utils/logger.js +0 -28
  114. package/src/utils/rootPath.js +0 -19
@@ -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-devops16.csez.zohocorpin.com:31025/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
+ };
@@ -0,0 +1,46 @@
1
+ const testSetup = require('../../fixtures/testSetup');
2
+ /**
3
+ * @typedef {Object|null} viewportConfig
4
+ * @property {number} width - width of the viewport
5
+ * @property {number} height - height of the viewport
6
+ */
7
+ /**
8
+ * Represents the user configuration object.
9
+ * @typedef {Object} UserConfig
10
+ * @property {string} headless - Headless Browsers mode.
11
+ * @property {number} trace - trace for test cases.
12
+ * @property {boolean} video - video for test cases,
13
+ * @property {boolean} debug - debug mode
14
+ * @property {string} mode: mode in which the test cases needs to run
15
+ * @property {boolean} isAuthMode - Auth Mode. config whether authentication step needed before running test cases
16
+ * @property {string} authFilePath - File Path where the cookies stored
17
+ * @property {any} browsers: List of browsers
18
+ * @property {string} openReportOn: default Option value (never, on-failure and always)
19
+ * @property {any} reportPath : directory where report is generate
20
+ * @property {boolean} bddMode: Feature files needs to be processed
21
+ * @property {number} expectTimeout: time in milliseconds which the expect condition should fail
22
+ * @property {number} testTimeout: time in milliseconds which the test should fail
23
+ * @property {Object} additionalPages: custom pages configuration
24
+ * @property {string} featureFilesFolder: folder name under which feature-files will be placed. Default is feature-files
25
+ * @property {string} stepDefinitionsFolder: folder name under which step implementations will be placed. Default is steps
26
+ * @property {viewportConfig} viewport: viewport configuration for the browser. Default is { width: 1280, height: 720 }
27
+ * @property {string} testIdAttribute: Change the default data-testid attribute. configure what attribute to search while calling getByTestId
28
+ */
29
+
30
+ /**
31
+ * @type {UserConfig}
32
+ */
33
+ module.exports = {
34
+ headless: false,
35
+ browsers: ['Chrome', 'Firefox', 'Safari', 'Edge'],
36
+ mode: 'dev',
37
+ isAuthMode: true,
38
+ authFilePath: 'uat/playwright/.auth/user.json',
39
+ trace: true,
40
+ video: true,
41
+ bddMode: true,
42
+ featureFilesFolder: 'feature-files',
43
+ stepDefinitionsFolder: 'steps',
44
+ viewport: { width: 1280, height: 720 },
45
+ testSetup
46
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = setupProject;
8
+ var _fs = require("fs");
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _logger = require("../utils/logger");
11
+ function getScriptsToBeAdded() {
12
+ return {
13
+ "uat": "ZDTestingFramework test --mode=dev --headed",
14
+ "uat-debug": "ZDTestingFramework test --mode=dev --debug",
15
+ "uat-validate": "ZDTestingFramework validate",
16
+ "uat-report": "ZDTestingFramework report --port=9009",
17
+ "codegen": "ZDTestingFramework codegen deskclientapp.localzoho.com/agent"
18
+ };
19
+ }
20
+ function updatePackageJSONScripts() {
21
+ const packageJsonPath = _path.default.resolve(process.cwd(), './package.json');
22
+ if ((0, _fs.existsSync)(packageJsonPath)) {
23
+ const packageContents = (0, _fs.readFileSync)(packageJsonPath);
24
+ const configJSON = JSON.parse(packageContents);
25
+ const {
26
+ scripts = {}
27
+ } = configJSON;
28
+ const modifiedScripts = {
29
+ ...scripts,
30
+ ...getScriptsToBeAdded()
31
+ };
32
+ const modifiedConfigJSON = {
33
+ ...configJSON,
34
+ scripts: modifiedScripts
35
+ };
36
+ (0, _fs.writeFileSync)(packageJsonPath, JSON.stringify(modifiedConfigJSON, null, 2));
37
+ } else {
38
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Unable to find package json. Run init command in the root path of the project.');
39
+ }
40
+ }
41
+ function createFolderForUAT() {
42
+ const uatFolder = _path.default.resolve(process.cwd(), 'uat');
43
+ if ((0, _fs.existsSync)(uatFolder)) {
44
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Uat Folder already Exists.');
45
+ } else {
46
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Uat Folder');
47
+ (0, _fs.mkdirSync)(uatFolder);
48
+ }
49
+ }
50
+ function getSetupFileAsString(fileName) {
51
+ return (0, _fs.readFileSync)(_path.default.resolve(__dirname, './samples/', fileName)).toString();
52
+ }
53
+ function createUatConfig() {
54
+ const uatConfigPath = _path.default.resolve(process.cwd(), 'uat.config.js');
55
+ if ((0, _fs.existsSync)(uatConfigPath)) {
56
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Uat Config already Exists.');
57
+ } else {
58
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Uat config file...');
59
+ (0, _fs.writeFileSync)(uatConfigPath, getSetupFileAsString('uat-config-sample.js'), null, 2);
60
+ }
61
+ }
62
+ function createAuthenticationFile() {
63
+ const isUATexist = _path.default.resolve(process.cwd(), 'uat');
64
+ if ((0, _fs.existsSync)(isUATexist)) {
65
+ try {
66
+ if (!(0, _fs.existsSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'))) {
67
+ (0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'));
68
+ }
69
+ if (!(0, _fs.existsSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'))) {
70
+ (0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'), {
71
+ recursive: true
72
+ });
73
+ }
74
+ (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'auth.setup.js'), getSetupFileAsString('auth-setup-sample.js'), null, 2);
75
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Authentication File ....');
76
+ (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'accountLogin.js'), getSetupFileAsString('accountLogin-sample.js'), null, 2);
77
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating login script File ....');
78
+ (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'testSetup.js'), getSetupFileAsString('testSetup-sample.js'), null, 2);
79
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating testSetup File ....');
80
+ } catch (err) {
81
+ _logger.Logger.error(err);
82
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat');
83
+ }
84
+ } else {
85
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Something went wrong. Please re-initialize the @zohodesk/testinglibrary');
86
+ }
87
+ }
88
+ function createConfigJson() {
89
+ const uatFolder = _path.default.resolve(process.cwd(), 'uat');
90
+ if ((0, _fs.existsSync)(uatFolder)) {
91
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating settings.json file inside UAT Folder');
92
+ if (!(0, _fs.existsSync)(_path.default.resolve(uatFolder, 'conf', 'default'))) {
93
+ (0, _fs.mkdirSync)(_path.default.resolve(uatFolder, 'conf', 'default'), {
94
+ recursive: true
95
+ });
96
+ }
97
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', './settings.json'), getSetupFileAsString('settings.json'), null, 2);
98
+ if (!(0, _fs.existsSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions'))) {
99
+ (0, _fs.mkdirSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions'), {
100
+ recursive: true
101
+ });
102
+ }
103
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions', 'free.json'), getSetupFileAsString('free-sample.json'), null, 2);
104
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions', 'index.js'), getSetupFileAsString('editions-index.js'), null, 2);
105
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'index.js'), getSetupFileAsString('actors-index.js'), null, 2);
106
+ } else {
107
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Something went wrong. Please re-initialize the @zohodesk/testinglibrary');
108
+ }
109
+ }
110
+ function setupProject() {
111
+ updatePackageJSONScripts();
112
+ createUatConfig();
113
+ createFolderForUAT();
114
+ createConfigJson();
115
+ createAuthenticationFile();
116
+ //updateGitIgnore()
117
+ // Create folder for playwright . Inside .auth folder needs to be created. user.json
118
+ // Add playwright and test-results to .gitignore
119
+ setTimeout(() => {
120
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Setup Project is Ready ..');
121
+ }, 2000);
122
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _tagProcessor = _interopRequireDefault(require("../../../../../src/core/playwright/tagProcessor"));
5
+ var _logger = require("../../../../utils/logger");
6
+ jest.mock('../../../../utils/logger');
7
+ describe('TagProcessor', () => {
8
+ const editionOrder = ['edition1', 'edition2', 'edition3', 'edition4'];
9
+ beforeEach(() => {
10
+ jest.clearAllMocks();
11
+ });
12
+ test('should return tagArgs if no edition is provided', () => {
13
+ const tagProcessor = new _tagProcessor.default(editionOrder);
14
+ const userArgs = {
15
+ tags: 'tag1',
16
+ edition: null
17
+ };
18
+ const result = tagProcessor.processTags(userArgs);
19
+ expect(result).toBe('tag1');
20
+ });
21
+ test('should handle a single edition with <= operator', () => {
22
+ const tagProcessor = new _tagProcessor.default(editionOrder);
23
+ const userArgs = {
24
+ tags: 'tag1',
25
+ edition: '<=edition2'
26
+ };
27
+ const result = tagProcessor.processTags(userArgs);
28
+ expect(result).toBe('tag1 and not (@edition_edition3 or @edition_edition4)');
29
+ });
30
+ test('should handle a single edition with >= operator', () => {
31
+ const tagProcessor = new _tagProcessor.default(editionOrder);
32
+ const userArgs = {
33
+ tags: 'tag1',
34
+ edition: '>=edition2'
35
+ };
36
+ const result = tagProcessor.processTags(userArgs);
37
+ expect(result).toBe('tag1 and not (@edition_edition1)');
38
+ });
39
+ test('should handle a single edition with < operator', () => {
40
+ const tagProcessor = new _tagProcessor.default(editionOrder);
41
+ const userArgs = {
42
+ tags: 'tag1',
43
+ edition: '<edition3'
44
+ };
45
+ const result = tagProcessor.processTags(userArgs);
46
+ expect(result).toBe('tag1 and not (@edition_edition3 or @edition_edition4)');
47
+ });
48
+ test('should handle a single edition with > operator', () => {
49
+ const tagProcessor = new _tagProcessor.default(editionOrder);
50
+ const userArgs = {
51
+ tags: 'tag1',
52
+ edition: '>edition1'
53
+ };
54
+ const result = tagProcessor.processTags(userArgs);
55
+ expect(result).toBe('tag1 and not (@edition_edition1)');
56
+ });
57
+ test('should handle a single edition with no operator', () => {
58
+ const tagProcessor = new _tagProcessor.default(editionOrder);
59
+ const userArgs = {
60
+ tags: 'tag1',
61
+ edition: 'edition2'
62
+ };
63
+ const result = tagProcessor.processTags(userArgs);
64
+ expect(result).toBe('tag1 and not (@edition_edition1 or @edition_edition3 or @edition_edition4)');
65
+ });
66
+ test('should log a message if edition is not found', () => {
67
+ const tagProcessor = new _tagProcessor.default(editionOrder);
68
+ const userArgs = {
69
+ tags: 'tag1',
70
+ edition: 'nonexistentEdition'
71
+ };
72
+ const result = tagProcessor.processTags(userArgs);
73
+ expect(result).toBe('tag1');
74
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.INFO_TYPE, expect.stringContaining('No matching editions for nonexistentEdition found.'));
75
+ });
76
+ test('should handle multiple editions', () => {
77
+ const tagProcessor = new _tagProcessor.default(editionOrder);
78
+ const userArgs = {
79
+ tags: 'tag1',
80
+ edition: 'edition1,edition3'
81
+ };
82
+ const result = tagProcessor.processTags(userArgs);
83
+ expect(result).toBe('tag1 and not (@edition_edition2 or @edition_edition4)');
84
+ });
85
+ test('should build tags correctly when tags are empty', () => {
86
+ const tagProcessor = new _tagProcessor.default(editionOrder);
87
+ const userArgs = {
88
+ tags: '',
89
+ edition: 'edition1'
90
+ };
91
+ const result = tagProcessor.processTags(userArgs);
92
+ expect(result).toBe('not (@edition_edition2 or @edition_edition3 or @edition_edition4)');
93
+ });
94
+ });
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _validateFeature = _interopRequireDefault(require("../../../../core/playwright/validateFeature"));
5
+ var _parseUserArgs = _interopRequireDefault(require("../../../../core/playwright/helpers/parseUserArgs"));
6
+ var _readConfigFile = require("../../../../core/playwright/readConfigFile");
7
+ var _tagProcessor = _interopRequireDefault(require("../../../../core/playwright/tagProcessor"));
8
+ var _testRunner = require("../../../../core/playwright/test-runner");
9
+ var _logger = require("../../../../utils/logger");
10
+ jest.mock('../../../../core/playwright/helpers/parseUserArgs', () => ({
11
+ __esModule: true,
12
+ default: jest.fn()
13
+ }));
14
+ jest.mock('../../../../core/playwright/readConfigFile');
15
+ jest.mock('../../../../core/playwright/tagProcessor');
16
+ jest.mock('../../../../core/playwright/test-runner');
17
+ jest.mock('../../../../utils/logger', () => ({
18
+ __esModule: true,
19
+ Logger: {
20
+ log: jest.fn(),
21
+ SUCCESS_TYPE: 'success',
22
+ FAILURE_TYPE: 'failure'
23
+ }
24
+ }));
25
+ describe('validateFeatureFiles', () => {
26
+ let tagProcessorInstance;
27
+ beforeEach(() => {
28
+ jest.clearAllMocks();
29
+ tagProcessorInstance = {
30
+ processTags: jest.fn()
31
+ };
32
+ _tagProcessor.default.mockImplementation(() => tagProcessorInstance);
33
+ });
34
+ test('runPreprocessing with correct arguments and log success', async () => {
35
+ const mockUserArgs = {
36
+ mode: 'dev'
37
+ };
38
+ _parseUserArgs.default.mockReturnValue(mockUserArgs);
39
+ const mockConfig = {
40
+ editionOrder: ["beta", "enterprice"]
41
+ };
42
+ _readConfigFile.generateConfigFromFile.mockReturnValue(mockConfig);
43
+ _readConfigFile.isUserConfigFileAvailable.mockReturnValue(true);
44
+ const mockTagArgs = ['@beta_admin'];
45
+ tagProcessorInstance.processTags.mockReturnValue(mockTagArgs);
46
+ _testRunner.runPreprocessing.mockResolvedValueOnce();
47
+ await (0, _validateFeature.default)();
48
+ expect(_parseUserArgs.default).toHaveBeenCalled();
49
+ expect(_readConfigFile.generateConfigFromFile).toHaveBeenCalled();
50
+ expect(_readConfigFile.isUserConfigFileAvailable).toHaveBeenCalled();
51
+ expect(tagProcessorInstance.processTags).toHaveBeenCalledWith(mockUserArgs);
52
+ expect(_testRunner.runPreprocessing).toHaveBeenCalledWith(mockTagArgs, expect.stringContaining('config-creator.js'));
53
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.SUCCESS_TYPE, 'Feature files validated successfully.');
54
+ });
55
+ test('runPreprocessing with playwright conf', async () => {
56
+ const mockTagArgs = ['@beta_admin'];
57
+ tagProcessorInstance.processTags.mockReturnValue(mockTagArgs);
58
+ _readConfigFile.isUserConfigFileAvailable.mockReturnValue(false);
59
+ _testRunner.runPreprocessing.mockResolvedValueOnce();
60
+ await (0, _validateFeature.default)();
61
+ expect(_testRunner.runPreprocessing).toHaveBeenCalledWith(mockTagArgs, expect.stringContaining('playwright.config.js'));
62
+ });
63
+ test('error when runPreprocessing fails', async () => {
64
+ const mockError = new Error('Test error');
65
+ _testRunner.runPreprocessing.mockRejectedValueOnce(mockError);
66
+ await await (0, _validateFeature.default)();
67
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.FAILURE_TYPE, `Error while validating the feature files - ${mockError}`);
68
+ });
69
+ });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _page = require("../../../../../core/playwright/builtInFixtures/page");
5
+ var _executionContext = _interopRequireDefault(require("../../../../../core/playwright/builtInFixtures/executionContext"));
6
+ jest.mock('../../../../../core/playwright/builtInFixtures/page');
7
+ describe('executionContext', () => {
8
+ test('should pass actorInfo with details from getCustomAccountDetails to use', async () => {
9
+ const mockTags = ['tag1', 'tag2'];
10
+ const mockActorInfo = {
11
+ id: '1',
12
+ edition: 'enterprise',
13
+ orgName: 'orgName',
14
+ profile: 'admin',
15
+ email: 'xxx.x+uat@zohotest.com'
16
+ };
17
+ _page.getCustomAccountDetails.mockReturnValue(mockActorInfo);
18
+ const use = jest.fn();
19
+ await _executionContext.default.executionContext({
20
+ $tags: mockTags
21
+ }, use);
22
+ expect(_page.getCustomAccountDetails).toHaveBeenCalledWith(mockTags);
23
+ expect(use).toHaveBeenCalledWith({
24
+ actorInfo: mockActorInfo
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ const Configuration = require("../../../../../core/playwright/configuration/Configuration");
4
+ const {
5
+ combineConfiguration
6
+ } = require("../../../../../core/playwright/configuration/ConfigurationHelper");
7
+ jest.mock('../../../../../core/playwright/configuration/ConfigurationHelper', () => ({
8
+ combineConfiguration: jest.fn()
9
+ }));
10
+ describe('Configuration Class', () => {
11
+ let config;
12
+ let sampleData;
13
+ beforeEach(() => {
14
+ // Sample data as a JSON object
15
+ sampleData = {
16
+ headless: false,
17
+ trace: true,
18
+ video: true,
19
+ bddMode: true
20
+ };
21
+
22
+ // Initialize the Configuration instance with sample data
23
+ config = new Configuration(sampleData);
24
+ });
25
+ test('should add new key-value pair to the configuration', () => {
26
+ config.add('newKey', 'newValue');
27
+ expect(config.get('newKey')).toBe('newValue');
28
+ });
29
+ test('should combine configurations correctly using addAll', () => {
30
+ const newConfig = new Configuration({
31
+ newKey1: 'newValue1',
32
+ trace: false // existing key to test override
33
+ });
34
+ const combinedConfig = {
35
+ headless: false,
36
+ trace: false,
37
+ // trace overridden
38
+ video: true,
39
+ bddMode: true,
40
+ newKey1: 'newValue1'
41
+ };
42
+ combineConfiguration.mockReturnValue(combinedConfig);
43
+ config.addAll(newConfig);
44
+ expect(combineConfiguration).toHaveBeenCalledWith(sampleData, newConfig.getAll());
45
+ expect(config.getAll()).toEqual(combinedConfig);
46
+ });
47
+ test('should return correct value for a given key', () => {
48
+ expect(config.get('headless')).toBe(false);
49
+ expect(config.get('trace')).toBe(true);
50
+ expect(config.get('video')).toBe(true);
51
+ expect(config.get('bddMode')).toBe(true);
52
+ });
53
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _fs = require("fs");
5
+ var _path = _interopRequireDefault(require("path"));
6
+ var _configFileNameProvider = require("../../../../../core/playwright/helpers/configFileNameProvider");
7
+ jest.mock('fs');
8
+ jest.mock('path');
9
+ const mockCwd = '/mock/current/directory';
10
+ _path.default.resolve = jest.fn();
11
+ process.cwd = jest.fn(() => mockCwd);
12
+ describe('getUATFileName', () => {
13
+ beforeEach(() => {
14
+ jest.clearAllMocks();
15
+ });
16
+ test('return the pipeline matched config files for pipeline matched files exists', () => {
17
+ const mode = 'cd';
18
+ const mockPath = `${mockCwd}/uat/conf/${mode}/uat.config.js`;
19
+ _fs.existsSync.mockReturnValue(true);
20
+ _path.default.resolve.mockImplementation((...args) => args.join('/'));
21
+ const result = (0, _configFileNameProvider.getUATFileName)(mode);
22
+ expect(_fs.existsSync).toHaveBeenCalledWith(mockPath);
23
+ expect(result).toBe(mockPath);
24
+ });
25
+ test('return the default config files for pipeline matched files not exists', () => {
26
+ const mode = 'ci';
27
+ const defaultPath = `${mockCwd}/uat/conf/default/uat.config.js`;
28
+ _fs.existsSync.mockReturnValue(false);
29
+ _path.default.resolve.mockImplementation((...args) => args.join('/'));
30
+ const result = (0, _configFileNameProvider.getUATFileName)(mode);
31
+ expect(_fs.existsSync).toHaveBeenCalledWith(`${mockCwd}/uat/conf/${mode}/uat.config.js`);
32
+ expect(result).toBe(defaultPath);
33
+ });
34
+ });