@zohodesk/testinglibrary 3.0.7 → 3.0.9

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/.gitlab-ci.yml CHANGED
@@ -18,14 +18,19 @@ default:
18
18
  paths:
19
19
  - node_modules
20
20
  - build
21
+ - npm-shrinkwrap.json
21
22
 
22
23
  # Install dependencies stage
23
24
  build:
24
25
  stage: build
25
26
  script:
27
+ - npm -v
28
+ - node -v
26
29
  - npm install --ignore-scripts
27
30
  - npm run build
28
31
  - npm install
32
+ - npm shrinkwrap
33
+ - npm run build
29
34
 
30
35
  # Unit tests stage
31
36
  unit:
@@ -101,7 +106,7 @@ uat-nobdd:
101
106
  script:
102
107
  - cd nobdd
103
108
  - npm install $(npm pack ../../testing-framework | tail -1)
104
- - output=$(npm run uatnobdd)
109
+ - output=$(npm run uatnobdd -- --headless)
105
110
  - echo "$output"
106
111
  - node ../ValidateUATReport.js nobdd
107
112
 
package/README.md CHANGED
@@ -29,6 +29,28 @@
29
29
 
30
30
  ## Version History
31
31
 
32
+ ### v3.0.8 - 25-12-2024
33
+
34
+ #### Enhancement
35
+ - Added support to disable headless mode using command line arguments
36
+ - Proper validation added for node 14 build process
37
+ - Removed unwanted uat.config.js files in test projects (examples / nobdd)
38
+
39
+ ### v0.2.9.2 - 22-11-2024
40
+
41
+ #### BugFix
42
+ - Implemented synchronization for the login process. This fix will help avoid login session-related failures in UAT.
43
+
44
+ ### v0.3.1 - 13-11-2024
45
+
46
+ #### Issue Fix
47
+ - Adding bddmode to get the fixtures.
48
+
49
+ ### v0.2.9.1 - 14-11-2024
50
+
51
+ #### Enhancement
52
+ - Beta feature Actors and edition configurations are unified
53
+
32
54
  ### v0.2.9 - 25-10-2024
33
55
 
34
56
  #### Feature
@@ -60,6 +82,11 @@
60
82
  #### Issue Fix
61
83
  - Adding bddmode to get the fixtures.
62
84
 
85
+ ### v0.3.3 - 27-11-2024
86
+
87
+ #### Feature
88
+ - Custom report integration support (ReportPortal)
89
+
63
90
  ### v0.2.9.1 - 14-11-2024
64
91
 
65
92
  #### Enhancement
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = void 0;
8
7
  var _auth = require("../helpers/auth");
9
- var _getUrlOrigin = _interopRequireDefault(require("../helpers/auth/getUrlOrigin"));
10
8
  var _readConfigFile = require("../readConfigFile");
11
9
  /* eslint-disable global-require */
12
10
 
@@ -29,84 +27,68 @@ function getCustomAccountDetails(tags) {
29
27
  const user = (0, _auth.getUserForSelectedEditionAndProfile)(editionInfo, profileInfo, betaFeature, portalInfo);
30
28
  return user;
31
29
  }
32
- return null;
30
+ return (0, _auth.getDefaultActor)();
33
31
  }
34
32
  const {
35
33
  testSetup
36
34
  } = (0, _readConfigFile.generateConfigFromFile)();
37
- async function performDefaultPageSteps({
38
- context,
39
- $tags,
40
- page
41
- }) {
42
- if (testSetup.page && typeof testSetup.page === 'function') {
43
- await testSetup.page({
44
- context,
45
- $tags,
46
- page
47
- });
35
+ async function loginSteps(pageDetail) {
36
+ const {
37
+ page
38
+ } = pageDetail;
39
+ if (testSetup.loginSteps && typeof testSetup.loginSteps === 'function') {
40
+ return await testSetup.loginSteps(pageDetail);
48
41
  } else {
49
42
  await page.goto(process.env.domain);
50
43
  }
51
44
  }
52
- async function verifyPageIsLoaded(page) {
53
- const urlOrigin = (0, _getUrlOrigin.default)(page.url());
54
- const domainOrigin = (0, _getUrlOrigin.default)(process.env.domain);
55
- if (urlOrigin === domainOrigin) {
56
- return true;
45
+ async function performDefaultPageSteps(testInfo) {
46
+ if (testSetup.page && typeof testSetup.page === 'function') {
47
+ await testSetup.page(testInfo);
48
+ }
49
+ }
50
+ async function verifyPageIsLoaded(testInfo) {
51
+ if (testSetup.validateLogin && typeof testSetup.validateLogin === 'function') {
52
+ return await testSetup.validateLogin(testInfo);
57
53
  }
58
- return false;
54
+ return true;
59
55
  }
60
56
  var _default = exports.default = {
61
57
  page: async ({
62
58
  context,
63
59
  $tags,
64
60
  page
65
- }, use) => {
66
- const {
67
- isAuthMode
68
- } = (0, _readConfigFile.generateConfigFromFile)();
69
- if (!isAuthMode) {
70
- await use(page);
71
- return;
72
- }
73
-
74
- //This block is used to skip the login process if the @unauthenticated tag is added to the script
75
- if ($tags.includes('@unauthenticated')) {
76
- await context.clearCookies();
77
- await use(page);
78
- return;
79
- }
80
- const testPortalDetails = getCustomAccountDetails($tags);
81
- if (testPortalDetails === null) {
82
- await performDefaultPageSteps({
83
- context,
84
- $tags,
85
- page
86
- });
87
- const user = (0, _auth.getDefaultActor)();
88
- process.env.actorInfo = JSON.stringify(user);
89
- await use(page);
90
- } else {
91
- await context.clearCookies();
61
+ }, use, testInfo) => {
62
+ let testPortalDetails = getCustomAccountDetails($tags);
63
+ let testDetails = {
64
+ page,
65
+ $tags,
66
+ context,
67
+ ...testPortalDetails
68
+ };
69
+ try {
70
+ //This block is used to skip the login process if the @unauthenticated tag is added to the script
71
+ if ($tags.includes('@unauthenticated')) {
72
+ await context.clearCookies();
73
+ return;
74
+ }
92
75
  const {
93
- email,
94
- password
95
- } = testPortalDetails;
96
- await (0, _auth.performLoginSteps)({
97
- page,
98
- authFilePrefix: email,
99
- useremail: email,
100
- password: password
101
- }, async () => {
102
- return await verifyPageIsLoaded(page);
103
- });
104
- process.env.actorInfo = JSON.stringify(testPortalDetails);
105
- await performDefaultPageSteps({
106
- context,
107
- $tags,
108
- page
109
- });
76
+ isAuthMode
77
+ } = (0, _readConfigFile.generateConfigFromFile)();
78
+ if (!isAuthMode) {
79
+ return;
80
+ }
81
+ if (testPortalDetails && testInfo.project.name !== 'setup') {
82
+ await context.clearCookies();
83
+ await (0, _auth.performLoginSteps)(testDetails, async testInfo => {
84
+ return await verifyPageIsLoaded(testInfo);
85
+ }, loginSteps);
86
+ process.env.actorInfo = JSON.stringify(testPortalDetails);
87
+ }
88
+ } catch (e) {
89
+ console.error('Error during page', e);
90
+ } finally {
91
+ await performDefaultPageSteps(testDetails);
110
92
  await use(page);
111
93
  await context.close();
112
94
  }
@@ -9,6 +9,7 @@ var _path = _interopRequireDefault(require("path"));
9
9
  var _fileUtils = require("../../utils/fileUtils");
10
10
  var _logger = require("../../utils/logger");
11
11
  var _readConfigFile = require("./readConfigFile");
12
+ var _checkAuthDirectory = require("./helpers/checkAuthDirectory");
12
13
  function deleteAuthFiles(authFilePath) {
13
14
  authFilePath = _path.default.resolve(process.cwd(), authFilePath);
14
15
  const authFileFolder = _path.default.dirname(authFilePath);
@@ -24,6 +25,11 @@ function deleteGeneratedFeatures() {
24
25
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting generated features at ${featuresGenPath}`);
25
26
  (0, _fileUtils.deleteFolder)(featuresGenPath);
26
27
  }
28
+ function deleteLockFiles() {
29
+ const lockFilePath = (0, _checkAuthDirectory.getLockDirectoryPath)();
30
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Deleting lock files at ${lockFilePath}`);
31
+ (0, _fileUtils.deleteFolder)(lockFilePath);
32
+ }
27
33
  function clearCaches() {
28
34
  try {
29
35
  const {
@@ -33,6 +39,7 @@ function clearCaches() {
33
39
  deleteAuthFiles(authFilePath);
34
40
  deletePlaywrightReport(reportPath);
35
41
  deleteGeneratedFeatures();
42
+ deleteLockFiles();
36
43
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Caches Cleared. Now you can try running npm run uat');
37
44
  } catch (err) {
38
45
  _logger.Logger.error(err);
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CUSTOM_COMMANDS = void 0;
7
- const CUSTOM_COMMANDS = exports.CUSTOM_COMMANDS = ['mode', 'tags', 'edition', 'browsers', 'filePath'];
7
+ const CUSTOM_COMMANDS = exports.CUSTOM_COMMANDS = ['mode', 'tags', 'edition', 'browsers', 'filePath', 'headless'];
@@ -8,41 +8,38 @@ exports.default = void 0;
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  var _fileMutex = _interopRequireDefault(require("../fileMutex"));
10
10
  var _fileMutexConfig = require("../../constants/fileMutexConfig");
11
- var _accountLogin = _interopRequireDefault(require("./accountLogin"));
12
11
  var _checkAuthCookies = require("./checkAuthCookies");
13
12
  var _checkAuthDirectory = require("../checkAuthDirectory");
14
13
  /* eslint-disable no-console */
15
14
 
16
- async function performLoginSteps({
17
- page,
18
- authFilePrefix,
19
- useremail,
20
- password
21
- }, isLoggedIn) {
15
+ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
16
+ let {
17
+ page,
18
+ authFilePrefix,
19
+ email
20
+ } = testInfo;
21
+ authFilePrefix = authFilePrefix || email;
22
22
  const authFile = _path.default.resolve(_path.default.join((0, _checkAuthCookies.getAuthFileDirectory)(), `${authFilePrefix}-cookies.json`));
23
- const lockFileName = useremail.replace(/[@.]/g, '_');
23
+ const lockFileName = email.replace(/[@.]/g, '_');
24
24
  const fileMutex = new _fileMutex.default((0, _checkAuthDirectory.getLockDirectoryPath)(), lockFileName, _fileMutexConfig.LOGIN_MUTEX_TIMEOUT);
25
25
  try {
26
26
  await fileMutex.acquire();
27
27
  await (0, _checkAuthCookies.loadCookiesIfPresent)(page, authFile);
28
- await page.goto(process.env.domain);
29
- await Promise.race([page.waitForNavigation(), page.waitForLoadState('networkidle'), page.waitForTimeout(5000)]);
30
- const isAlreadyLoggedIn = await isLoggedIn(page);
28
+ const isAlreadyLoggedIn = await isLoggedIn(testInfo);
31
29
  if (!isAlreadyLoggedIn) {
32
- await (0, _accountLogin.default)(page, useremail, password);
33
- await page.goto(process.env.domain);
34
- await isLoggedIn(page);
30
+ await loginSteps(testInfo);
31
+ await isLoggedIn(testInfo);
35
32
  await page.context().storageState({
36
33
  path: authFile
37
34
  });
38
35
  }
39
36
  } catch (error) {
40
- console.error(`Error during login for ${useremail}:`, error);
37
+ console.error(`Error during login for ${email}:`, error);
41
38
  } finally {
42
39
  try {
43
40
  await fileMutex.release();
44
41
  } catch (releaseError) {
45
- console.error(`Error releasing lock for ${useremail}:`, releaseError);
42
+ console.error(`Error releasing lock for ${email}:`, releaseError);
46
43
  }
47
44
  }
48
45
  }
@@ -16,7 +16,7 @@ function getUATFileName(mode) {
16
16
  if (_fs.default.existsSync(uatConfFilePath)) {
17
17
  return uatConfFilePath;
18
18
  }
19
- return _path.default.resolve(process.cwd(), `uat.config.js`);
19
+ return _path.default.resolve(process.cwd(), `uat/conf/default/uat.config.js`);
20
20
  }
21
21
  function getEnvConfigFilePath(mode) {
22
22
  const confFilePath = _path.default.resolve(process.cwd(), `uat/conf/${mode}/settings.json`);
@@ -21,13 +21,13 @@ class FileMutex {
21
21
  }
22
22
  async acquire() {
23
23
  _assertClassBrand(_FileMutex_brand, this, _createDirectoryIfNotExist).call(this);
24
- const lockFilePath = _path.default.resolve(this.directory, this.lockFileName);
24
+ const lockFilePath = _assertClassBrand(_FileMutex_brand, this, _getLockFilePath).call(this);
25
25
  try {
26
26
  if (!(0, _fs.existsSync)(lockFilePath)) {
27
27
  console.log(`[DEBUG] Creating missing lock file:`, this.lockFileName);
28
28
  (0, _fs.writeFileSync)(lockFilePath, 'locked');
29
29
  }
30
- await _properLockfile.default.lock(_assertClassBrand(_FileMutex_brand, this, _getLockFilePath).call(this), this.options);
30
+ await _properLockfile.default.lock(lockFilePath, this.options);
31
31
  } catch (err) {
32
32
  throw new Error(`Failed to acquire lock after ${this.options.retries.retries} attempts: ${err.message}`);
33
33
  }
@@ -25,7 +25,8 @@ const {
25
25
  featureFilesFolder,
26
26
  stepDefinitionsFolder,
27
27
  testIdAttribute,
28
- globalTimeout
28
+ globalTimeout,
29
+ customReporter
29
30
  } = uatConfig;
30
31
  const projects = (0, _configUtils.getProjects)({
31
32
  browsers,
@@ -45,6 +46,15 @@ const use = {
45
46
  viewport,
46
47
  testIdAttribute
47
48
  };
49
+ let reporter = [['html', {
50
+ outputFolder: reportPath,
51
+ open: openReportOn
52
+ }], ['list'], ['json', {
53
+ outputFile: _path.default.join(process.cwd(), 'uat', 'test-results', 'test-results.json')
54
+ }], ['./custom-reporter.js']];
55
+ if (customReporter) {
56
+ reporter = [customReporter, ...reporter];
57
+ }
48
58
 
49
59
  /**
50
60
  * Playwright configuration object
@@ -57,10 +67,7 @@ function getPlaywrightConfig() {
57
67
  globalTimeout: globalTimeout || 3600000,
58
68
  outputDir: _path.default.join(process.cwd(), 'uat', 'test-results'),
59
69
  fullyParallel: true,
60
- reporter: [['html', {
61
- outputFolder: reportPath,
62
- open: openReportOn
63
- }], ['list'], ['./custom-reporter.js']],
70
+ reporter,
64
71
  timeout: testTimeout,
65
72
  expect: {
66
73
  timeout: expectTimeout
package/build/index.js CHANGED
@@ -70,6 +70,12 @@ Object.defineProperty(exports, "performLoginSteps", {
70
70
  return _index.performLoginSteps;
71
71
  }
72
72
  });
73
+ Object.defineProperty(exports, "setup", {
74
+ enumerable: true,
75
+ get: function () {
76
+ return _index.setup;
77
+ }
78
+ });
73
79
  Object.defineProperty(exports, "test", {
74
80
  enumerable: true,
75
81
  get: function () {
@@ -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;
@@ -5,17 +5,11 @@ import {
5
5
  getDefaultActor
6
6
  } from '@zohodesk/testinglibrary/helpers';
7
7
 
8
- const user = getDefaultActor();
8
+ import { loginSteps , validateLogin } from './testSetup';
9
9
 
10
- async function verifyPageIsLoaded(page) {
11
- //Implement your validation steps here
12
- //Refer desk_client_app auth.setup.js
13
- return true;
14
- }
10
+ const user = getDefaultActor();
15
11
 
16
12
  setup(`${user.edition} - Authentication`, async ({ page }) => {
17
-
18
13
  //Implement performLoginSteps here
19
- const { email, password } = user;
20
- await performLoginSteps({ },verifyPageIsLoaded );
21
- });
14
+ await performLoginSteps({page, ...user},validateLogin ,loginSteps);
15
+ });
@@ -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
+ };
@@ -1,3 +1,4 @@
1
+ const testSetup = require('../../fixtures/testSetup');
1
2
  /**
2
3
  * @typedef {Object|null} viewportConfig
3
4
  * @property {number} width - width of the viewport
@@ -40,5 +41,6 @@ module.exports = {
40
41
  bddMode: true,
41
42
  featureFilesFolder: 'feature-files',
42
43
  stepDefinitionsFolder: 'steps',
43
- viewport: { width: 1280, height: 720 }
44
+ viewport: { width: 1280, height: 720 },
45
+ testSetup
44
46
  }
@@ -73,6 +73,10 @@ function createAuthenticationFile() {
73
73
  }
74
74
  (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'auth.setup.js'), getSetupFileAsString('auth-setup-sample.js'), null, 2);
75
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 ....');
76
80
  } catch (err) {
77
81
  _logger.Logger.error(err);
78
82
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat');
@@ -24,7 +24,7 @@ describe('getUATFileName', () => {
24
24
  });
25
25
  test('return the default config files for pipeline matched files not exists', () => {
26
26
  const mode = 'ci';
27
- const defaultPath = `${mockCwd}/uat.config.js`;
27
+ const defaultPath = `${mockCwd}/uat/conf/default/uat.config.js`;
28
28
  _fs.existsSync.mockReturnValue(false);
29
29
  _path.default.resolve.mockImplementation((...args) => args.join('/'));
30
30
  const result = (0, _configFileNameProvider.getUATFileName)(mode);