@zohodesk/testinglibrary 2.9.4 → 2.9.6

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
@@ -14,18 +14,23 @@ stages:
14
14
 
15
15
  default:
16
16
  cache:
17
- key: build-cache
17
+ key: node14-build-cache
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:
@@ -45,9 +50,7 @@ uat-auth:
45
50
  - npm install $(npm pack ../../testing-framework | tail -1)
46
51
  - output=$(npm run uatauth)
47
52
  - echo "$output"
48
- - if [[ "$output" == *"failed"* ]]; then
49
- - exit 1
50
- - fi
53
+ - node ../ValidateUATReport.js examples
51
54
 
52
55
  artifacts:
53
56
  when: always
@@ -61,9 +64,7 @@ uat-noauth:
61
64
  - npm install $(npm pack ../../testing-framework | tail -1)
62
65
  - output=$(npm run uatnoauth)
63
66
  - echo "$output"
64
- - if [[ "$output" == *"failed"* ]]; then
65
- - exit 1
66
- - fi
67
+ - node ../ValidateUATReport.js examples
67
68
 
68
69
  artifacts:
69
70
  when: always
@@ -77,9 +78,7 @@ uat-profile:
77
78
  - npm install $(npm pack ../../testing-framework | tail -1)
78
79
  - output=$(npm run uatprofile)
79
80
  - echo "$output"
80
- - if [[ "$output" == *"failed"* ]]; then
81
- - exit 1
82
- - fi
81
+ - node ../ValidateUATReport.js examples
83
82
 
84
83
  artifacts:
85
84
  when: always
@@ -89,17 +88,12 @@ uat-profile:
89
88
 
90
89
  uat-unauth:
91
90
  stage: uat
92
- image: repository.desk.csez.zohocorpin.com/base-image/testing-framework-gitlab-runne-base:v2
93
91
  script:
94
- - npm install
95
- - npm run build
96
92
  - cd examples
97
93
  - npm install $(npm pack ../../testing-framework | tail -1)
98
94
  - output=$(npm run uatunauth)
99
95
  - echo "$output"
100
- - if [[ "$output" == *"failed"* ]]; then
101
- - exit 1
102
- - fi
96
+ - node ../ValidateUATReport.js examples
103
97
 
104
98
 
105
99
  artifacts:
@@ -112,11 +106,9 @@ uat-nobdd:
112
106
  script:
113
107
  - cd nobdd
114
108
  - npm install $(npm pack ../../testing-framework | tail -1)
115
- - output=$(npm run uatnobdd)
109
+ - output=$(npm run uatnobdd -- --headless)
116
110
  - echo "$output"
117
- - if [[ "$output" == *"failed"* ]]; then
118
- - exit 1
119
- - fi
111
+ - node ../ValidateUATReport.js nobdd
120
112
 
121
113
 
122
114
  artifacts:
@@ -34,6 +34,16 @@ function getCustomAccountDetails(tags) {
34
34
  const {
35
35
  testSetup
36
36
  } = (0, _readConfigFile.generateConfigFromFile)();
37
+ async function loginSteps(pageDetail) {
38
+ const {
39
+ page
40
+ } = pageDetail;
41
+ if (testSetup.loginSteps && typeof testSetup.loginSteps === 'function') {
42
+ return await testSetup.loginSteps(pageDetail);
43
+ } else {
44
+ await page.goto(process.env.domain);
45
+ }
46
+ }
37
47
  async function performDefaultPageSteps({
38
48
  context,
39
49
  $tags,
@@ -49,13 +59,11 @@ async function performDefaultPageSteps({
49
59
  await page.goto(process.env.domain);
50
60
  }
51
61
  }
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;
62
+ async function verifyPageIsLoaded(testInfo) {
63
+ if (testSetup.validateLogin && typeof testSetup.validateLogin === 'function') {
64
+ return await testSetup.validateLogin(testInfo);
57
65
  }
58
- return false;
66
+ return true;
59
67
  }
60
68
  var _default = exports.default = {
61
69
  page: async ({
@@ -63,45 +71,37 @@ var _default = exports.default = {
63
71
  $tags,
64
72
  page
65
73
  }, 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();
74
+ try {
75
+ //This block is used to skip the login process if the @unauthenticated tag is added to the script
76
+ if ($tags.includes('@unauthenticated')) {
77
+ await context.clearCookies();
78
+ return;
79
+ }
92
80
  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);
81
+ isAuthMode
82
+ } = (0, _readConfigFile.generateConfigFromFile)();
83
+ if (!isAuthMode) {
84
+ return;
85
+ }
86
+ const testPortalDetails = getCustomAccountDetails($tags);
87
+ if (testPortalDetails) {
88
+ await context.clearCookies();
89
+ const {
90
+ email
91
+ } = testPortalDetails;
92
+ await (0, _auth.performLoginSteps)({
93
+ page,
94
+ $tags,
95
+ context,
96
+ ...testPortalDetails
97
+ }, async testInfo => {
98
+ return await verifyPageIsLoaded(testInfo);
99
+ }, loginSteps);
100
+ process.env.actorInfo = JSON.stringify(testPortalDetails);
101
+ }
102
+ } catch (e) {
103
+ console.error('Error during page', e);
104
+ } finally {
105
105
  await performDefaultPageSteps({
106
106
  context,
107
107
  $tags,
@@ -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,41 @@ 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
28
  await page.goto(process.env.domain);
29
29
  await Promise.race([page.waitForNavigation(), page.waitForLoadState('networkidle'), page.waitForTimeout(5000)]);
30
- const isAlreadyLoggedIn = await isLoggedIn(page);
30
+ const isAlreadyLoggedIn = await isLoggedIn(testInfo);
31
31
  if (!isAlreadyLoggedIn) {
32
- await (0, _accountLogin.default)(page, useremail, password);
32
+ await loginSteps(testInfo);
33
33
  await page.goto(process.env.domain);
34
- await isLoggedIn(page);
34
+ await isLoggedIn(testInfo);
35
35
  await page.context().storageState({
36
36
  path: authFile
37
37
  });
38
38
  }
39
39
  } catch (error) {
40
- console.error(`Error during login for ${useremail}:`, error);
40
+ console.error(`Error during login for ${email}:`, error);
41
41
  } finally {
42
42
  try {
43
43
  await fileMutex.release();
44
44
  } catch (releaseError) {
45
- console.error(`Error releasing lock for ${useremail}:`, releaseError);
45
+ console.error(`Error releasing lock for ${email}:`, releaseError);
46
46
  }
47
47
  }
48
48
  }
@@ -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
  }
@@ -10,12 +10,14 @@ class TagProcessor {
10
10
  _classPrivateMethodInitSpec(this, _TagProcessor_brand);
11
11
  this.editionOrder = editionOrder;
12
12
  }
13
- processTags(userArgs) {
14
- const tagArgs = userArgs['tags'] || '';
15
- const edition = userArgs['edition'] || null;
16
- if (!edition) return tagArgs;
13
+ processTags(config) {
14
+ const {
15
+ tags,
16
+ edition
17
+ } = config.getAll();
18
+ if (!edition) return tags;
17
19
  const editionsArray = edition.split(',');
18
- const editionTags = editionsArray.length === 1 ? _assertClassBrand(_TagProcessor_brand, this, _processSingleEdition).call(this, editionsArray[0], tagArgs) : _assertClassBrand(_TagProcessor_brand, this, _processMultipleEditions).call(this, editionsArray, tagArgs);
20
+ const editionTags = editionsArray.length === 1 ? _assertClassBrand(_TagProcessor_brand, this, _processSingleEdition).call(this, editionsArray[0], tags) : _assertClassBrand(_TagProcessor_brand, this, _processMultipleEditions).call(this, editionsArray, tags);
19
21
  return editionTags;
20
22
  }
21
23
  }
@@ -104,7 +104,7 @@ function main() {
104
104
  //This is only used for pass the user arguments to need places in legacy code. We need to rewamp that also.
105
105
  const userArgsObject = userArgConfig.getAll();
106
106
  const tagProcessor = new _tagProcessor.default(editionOrder);
107
- const tagArgs = tagProcessor.processTags(userArgsObject);
107
+ const tagArgs = tagProcessor.processTags(uatConfig);
108
108
  const runnerObj = new _Runner.default();
109
109
  runnerObj.setTagArgs(tagArgs);
110
110
  runnerObj.setUserArgs(userArgsObject);
@@ -2,6 +2,7 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  var _tagProcessor = _interopRequireDefault(require("../../../../../src/core/playwright/tagProcessor"));
5
+ var _Configuration = _interopRequireDefault(require("../../../../../src/core/playwright/configuration/Configuration.js"));
5
6
  var _logger = require("../../../../utils/logger");
6
7
  jest.mock('../../../../utils/logger');
7
8
  describe('TagProcessor', () => {
@@ -11,83 +12,83 @@ describe('TagProcessor', () => {
11
12
  });
12
13
  test('should return tagArgs if no edition is provided', () => {
13
14
  const tagProcessor = new _tagProcessor.default(editionOrder);
14
- const userArgs = {
15
+ const userArgs = new _Configuration.default({
15
16
  tags: 'tag1',
16
17
  edition: null
17
- };
18
+ });
18
19
  const result = tagProcessor.processTags(userArgs);
19
20
  expect(result).toBe('tag1');
20
21
  });
21
22
  test('should handle a single edition with <= operator', () => {
22
23
  const tagProcessor = new _tagProcessor.default(editionOrder);
23
- const userArgs = {
24
+ const userArgs = new _Configuration.default({
24
25
  tags: 'tag1',
25
26
  edition: '<=edition2'
26
- };
27
+ });
27
28
  const result = tagProcessor.processTags(userArgs);
28
29
  expect(result).toBe('tag1 and not (@edition_edition3 or @edition_edition4)');
29
30
  });
30
31
  test('should handle a single edition with >= operator', () => {
31
32
  const tagProcessor = new _tagProcessor.default(editionOrder);
32
- const userArgs = {
33
+ const userArgs = new _Configuration.default({
33
34
  tags: 'tag1',
34
35
  edition: '>=edition2'
35
- };
36
+ });
36
37
  const result = tagProcessor.processTags(userArgs);
37
38
  expect(result).toBe('tag1 and not (@edition_edition1)');
38
39
  });
39
40
  test('should handle a single edition with < operator', () => {
40
41
  const tagProcessor = new _tagProcessor.default(editionOrder);
41
- const userArgs = {
42
+ const userArgs = new _Configuration.default({
42
43
  tags: 'tag1',
43
44
  edition: '<edition3'
44
- };
45
+ });
45
46
  const result = tagProcessor.processTags(userArgs);
46
47
  expect(result).toBe('tag1 and not (@edition_edition3 or @edition_edition4)');
47
48
  });
48
49
  test('should handle a single edition with > operator', () => {
49
50
  const tagProcessor = new _tagProcessor.default(editionOrder);
50
- const userArgs = {
51
+ const userArgs = new _Configuration.default({
51
52
  tags: 'tag1',
52
53
  edition: '>edition1'
53
- };
54
+ });
54
55
  const result = tagProcessor.processTags(userArgs);
55
56
  expect(result).toBe('tag1 and not (@edition_edition1)');
56
57
  });
57
58
  test('should handle a single edition with no operator', () => {
58
59
  const tagProcessor = new _tagProcessor.default(editionOrder);
59
- const userArgs = {
60
+ const userArgs = new _Configuration.default({
60
61
  tags: 'tag1',
61
62
  edition: 'edition2'
62
- };
63
+ });
63
64
  const result = tagProcessor.processTags(userArgs);
64
65
  expect(result).toBe('tag1 and not (@edition_edition1 or @edition_edition3 or @edition_edition4)');
65
66
  });
66
67
  test('should log a message if edition is not found', () => {
67
68
  const tagProcessor = new _tagProcessor.default(editionOrder);
68
- const userArgs = {
69
+ const userArgs = new _Configuration.default({
69
70
  tags: 'tag1',
70
71
  edition: 'nonexistentEdition'
71
- };
72
+ });
72
73
  const result = tagProcessor.processTags(userArgs);
73
74
  expect(result).toBe('tag1');
74
75
  expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.INFO_TYPE, expect.stringContaining('No matching editions for nonexistentEdition found.'));
75
76
  });
76
77
  test('should handle multiple editions', () => {
77
78
  const tagProcessor = new _tagProcessor.default(editionOrder);
78
- const userArgs = {
79
+ const userArgs = new _Configuration.default({
79
80
  tags: 'tag1',
80
81
  edition: 'edition1,edition3'
81
- };
82
+ });
82
83
  const result = tagProcessor.processTags(userArgs);
83
84
  expect(result).toBe('tag1 and not (@edition_edition2 or @edition_edition4)');
84
85
  });
85
86
  test('should build tags correctly when tags are empty', () => {
86
87
  const tagProcessor = new _tagProcessor.default(editionOrder);
87
- const userArgs = {
88
+ const userArgs = new _Configuration.default({
88
89
  tags: '',
89
90
  edition: 'edition1'
90
- };
91
+ });
91
92
  const result = tagProcessor.processTags(userArgs);
92
93
  expect(result).toBe('not (@edition_edition2 or @edition_edition3 or @edition_edition4)');
93
94
  });