@zohodesk/testinglibrary 0.4.84-n18-experimental → 0.4.86-n18-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.
@@ -6,30 +6,23 @@ const {
6
6
  Given
7
7
  } = (0, _testinglibrary.createBdd)();
8
8
  BeforeScenario(async function ({
9
- actorCtx,
10
- page,
11
- context,
12
- browser,
13
- executionContext
9
+ actorCtx
14
10
  }) {
15
11
  // This will run before each scenario and set all the fixtures into this context
16
- this.page = page;
17
- this.context = context;
18
- this.browser = browser;
19
- this.executionContext = executionContext;
20
12
  this.setActor = async role => {
21
- const userPage = actorCtx.userPages.find(up => up.role === role);
13
+ const userPage = actorCtx.actorsObj[role];
22
14
  if (userPage) {
23
15
  this.page = userPage.page;
24
16
  this.context = userPage.context;
25
17
  this.browser = userPage.browser;
26
18
  this.executionContext = userPage.actorInfo;
27
19
  } else {
28
- throw new Error(`Actor ${role} not found`);
20
+ const availableRoles = Object.keys(actorCtx.actorsObj);
21
+ throw new Error(`Actor "${role}" not found in user pages. Available roles: [${availableRoles.join(', ')}]`);
29
22
  }
30
23
  };
31
24
  });
32
- Given("switch to {string} profile user page", async function ({
25
+ Given("access the {string} profile page", async function ({
33
26
  page
34
27
  }, userRole) {
35
28
  await this.setActor(userRole);
@@ -6,70 +6,44 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _logger = require("../../../utils/logger");
8
8
  var _customFixturesHelper = require("../helpers/customFixturesHelper");
9
- class actorContext {
9
+ var _loginDefaultStepsHelper = require("../helpers/auth/loginDefaultStepsHelper");
10
+ class additionalActorContext {
10
11
  constructor() {
11
- this.page = null;
12
- this.browser = null;
13
- this.context = null;
14
- this.actorInfo = null;
15
- this.userPages = [];
16
- this.actorsList = {};
12
+ this.actorsObj = {};
17
13
  }
18
- async setupAdditionalActors(browser, $tags, testInfo, defaultPage, defaultContext) {
19
- const actorInfoMap = (0, _customFixturesHelper.getCustomAccountDetails)($tags);
20
- const currentActor = actorInfoMap.additional;
21
- await Promise.all(Object.entries(currentActor).map(async ([role, actorInfo], index) => {
22
- let context, page;
23
- if (index === 0) {
24
- context = defaultContext;
25
- page = defaultPage;
26
- } else {
27
- context = await browser.newContext();
28
- page = await context.newPage();
29
- }
30
- let ctxTestDetails = {
31
- page,
32
- $tags,
33
- context,
34
- ...actorInfo
35
- };
36
- await (0, _customFixturesHelper.executeDefaultLoginSteps)(context, testInfo, ctxTestDetails, actorInfo);
37
- this.actorsList[role] = {
38
- role,
39
- browser,
40
- context,
41
- page,
42
- actorInfo,
43
- isPrimary: index === 0
44
- };
45
- await this.addUserPage(role, browser, page, context, actorInfo);
46
- }));
47
- for (const actorObj of Object.values(this.actorsList)) {
48
- await (0, _customFixturesHelper.performDefaultPageSteps)({
49
- context: actorObj.context,
50
- page: actorObj.page,
51
- $tags,
52
- ...actorObj.actorInfo
53
- });
14
+ async setupAdditionalActors(browser, $tags, testInfo) {
15
+ try {
16
+ const actorInfoMap = (0, _customFixturesHelper.getCustomAccountDetails)($tags);
17
+ const additionalActors = actorInfoMap.additional;
18
+ await Promise.all(Object.entries(additionalActors).map(async ([role, actorInfo]) => {
19
+ let context = await browser.newContext();
20
+ let page = await context.newPage();
21
+ let ctxTestDetails = {
22
+ page,
23
+ $tags,
24
+ context,
25
+ ...actorInfo
26
+ };
27
+ await (0, _loginDefaultStepsHelper.executeDefaultLoginSteps)(context, testInfo, ctxTestDetails, actorInfo);
28
+ this.actorsObj[role] = {
29
+ role,
30
+ browser,
31
+ context,
32
+ page,
33
+ actorInfo
34
+ };
35
+ }));
36
+ } catch (error) {
37
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Failed to setup additional actors:`, error);
38
+ throw error;
54
39
  }
55
40
  }
56
- async addUserPage(role, browser, page, context, actorInfo) {
57
- this.userPages.push({
58
- role,
59
- browser,
60
- page,
61
- context,
62
- actorInfo
63
- });
64
- }
65
41
  async cleanup() {
66
- for (const actor of Object.values(this.actorsList)) {
67
- if (!actor.isPrimary && actor.context) {
68
- try {
69
- await actor.context.close();
70
- } catch (error) {
71
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Failed to close context for actor ${actor.role}:`, error);
72
- }
42
+ for (const actor of Object.values(this.actorsObj)) {
43
+ try {
44
+ await actor.context.close();
45
+ } catch (error) {
46
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Failed to close context for actor ${actor.role}:`, error);
73
47
  }
74
48
  }
75
49
  }
@@ -77,12 +51,10 @@ class actorContext {
77
51
  var _default = exports.default = {
78
52
  actorCtx: async ({
79
53
  $tags,
80
- browser,
81
- context,
82
- page
54
+ browser
83
55
  }, use, testInfo) => {
84
- const ctxObject = new actorContext();
85
- await ctxObject.setupAdditionalActors(browser, $tags, testInfo, page, context);
56
+ const ctxObject = new additionalActorContext();
57
+ await ctxObject.setupAdditionalActors(browser, $tags, testInfo);
86
58
  await use(ctxObject);
87
59
  await ctxObject.cleanup();
88
60
  }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _customFixturesHelper = require("../helpers/customFixturesHelper");
7
+ var _loginDefaultStepsHelper = require("../helpers/auth/loginDefaultStepsHelper");
8
8
  /* eslint-disable global-require */
9
9
  var _default = exports.default = {
10
10
  page: async ({
@@ -26,11 +26,11 @@ var _default = exports.default = {
26
26
  await context.clearCookies();
27
27
  return;
28
28
  }
29
- await (0, _customFixturesHelper.executeDefaultLoginSteps)(context, testInfo, testDetails, testPortalDetails);
29
+ await (0, _loginDefaultStepsHelper.executeDefaultLoginSteps)(context, testInfo, testDetails, testPortalDetails);
30
30
  } catch (e) {
31
31
  console.error('Error during page', e);
32
32
  } finally {
33
- await (0, _customFixturesHelper.performDefaultPageSteps)(testDetails);
33
+ await (0, _loginDefaultStepsHelper.performDefaultPageSteps)(testDetails);
34
34
  await use(page);
35
35
  await context.close();
36
36
  }
@@ -7,11 +7,12 @@ exports.additionProfiles = additionProfiles;
7
7
  var _getUsers = require("./auth/getUsers");
8
8
  function additionProfiles(tags, editionInfo, betaFeature, portalInfo) {
9
9
  const additionalProfileTags = tags.filter(tag => tag.startsWith('@additional_profile_'));
10
- let additionalProfileActors = [];
10
+ let additionalProfileActors = {};
11
11
  if (additionalProfileTags.length > 0 && editionInfo) {
12
- additionalProfileActors = additionalProfileTags.map(tag => {
12
+ additionalProfileTags.forEach(tag => {
13
13
  const additionalProfile = tag.replace('@additional_profile_', '');
14
- return (0, _getUsers.getUserForSelectedEditionAndProfile)(editionInfo, additionalProfile, betaFeature, portalInfo);
14
+ const actorDetails = (0, _getUsers.getUserForSelectedEditionAndProfile)(editionInfo, additionalProfile, betaFeature, portalInfo);
15
+ additionalProfileActors[additionalProfile] = actorDetails;
15
16
  });
16
17
  }
17
18
  return additionalProfileActors;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.executeDefaultLoginSteps = executeDefaultLoginSteps;
7
+ exports.loginSteps = loginSteps;
8
+ exports.performDefaultPageSteps = performDefaultPageSteps;
9
+ exports.verifyPageIsLoaded = verifyPageIsLoaded;
10
+ var _auth = require("../auth");
11
+ var _readConfigFile = require("../../readConfigFile");
12
+ let {
13
+ testSetup,
14
+ isAuthMode
15
+ } = (0, _readConfigFile.generateConfigFromFile)();
16
+ async function loginSteps(pageDetail) {
17
+ const {
18
+ page
19
+ } = pageDetail;
20
+ if (testSetup.loginSteps && typeof testSetup.loginSteps === 'function') {
21
+ return await testSetup.loginSteps(pageDetail);
22
+ } else {
23
+ await page.goto(process.env.domain);
24
+ }
25
+ }
26
+ async function performDefaultPageSteps(testInfo) {
27
+ if (testSetup.page && typeof testSetup.page === 'function') {
28
+ await testSetup.page(testInfo);
29
+ }
30
+ }
31
+ async function verifyPageIsLoaded(testInfo) {
32
+ if (testSetup.validateLogin && typeof testSetup.validateLogin === 'function') {
33
+ return await testSetup.validateLogin(testInfo);
34
+ }
35
+ return true;
36
+ }
37
+ async function executeDefaultLoginSteps(context, testInfo, testDetails, testPortalDetails) {
38
+ if (!isAuthMode) {
39
+ return;
40
+ }
41
+ try {
42
+ const projectName = testInfo.project.name;
43
+ if (testPortalDetails && projectName !== 'setup' && projectName !== 'cleanup') {
44
+ await context.clearCookies();
45
+ await (0, _auth.performLoginSteps)(testDetails, async testInfo => {
46
+ return await verifyPageIsLoaded(testInfo);
47
+ }, loginSteps);
48
+ process.env.actorInfo = JSON.stringify(testPortalDetails);
49
+ }
50
+ } catch (error) {
51
+ Logger.log(Logger.FAILURE_TYPE, 'Error while executing the default login steps:', error);
52
+ }
53
+ }
@@ -3,21 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.executeDefaultLoginSteps = executeDefaultLoginSteps;
7
6
  exports.getCustomAccountDetails = getCustomAccountDetails;
8
- exports.loginSteps = loginSteps;
9
- exports.performDefaultPageSteps = performDefaultPageSteps;
10
- exports.verifyPageIsLoaded = verifyPageIsLoaded;
11
7
  var _auth = require("../helpers/auth");
12
8
  var _additionalProfiles = require("../helpers/additionalProfiles");
13
- var _readConfigFile = require("../readConfigFile");
14
9
  var _logger = require("../../../utils/logger");
15
10
  /* eslint-disable global-require */
16
11
 
17
- let {
18
- testSetup,
19
- isAuthMode
20
- } = (0, _readConfigFile.generateConfigFromFile)();
21
12
  function getTagInputFromSelectedTags(tags, inputString) {
22
13
  const selectedTag = [...tags].reverse().find(tag => tag.startsWith(inputString));
23
14
  let tagInput = null;
@@ -36,13 +27,7 @@ function getCustomAccountDetails(tags) {
36
27
  const profileInfo = getTagInputFromSelectedTags(filteredTags, '@profile');
37
28
  const editionInfo = getTagInputFromSelectedTags(filteredTags, '@edition');
38
29
  const mainActor = (0, _auth.getUserForSelectedEditionAndProfile)(editionInfo, profileInfo, betaFeature, portalInfo);
39
- const additionalProfileActors = (0, _additionalProfiles.additionProfiles)(tags, editionInfo, betaFeature, portalInfo);
40
- const additionalProfileTags = tags.filter(tag => tag.startsWith('@additional_profile_'));
41
- const additionalActors = {};
42
- additionalProfileTags.forEach((tag, index) => {
43
- const profileName = tag.replace('@additional_profile_', '');
44
- additionalActors[profileName] = additionalProfileActors[index];
45
- });
30
+ const additionalActors = (0, _additionalProfiles.additionProfiles)(tags, editionInfo, betaFeature, portalInfo);
46
31
  return {
47
32
  main: mainActor,
48
33
  additional: additionalActors
@@ -55,42 +40,4 @@ function getCustomAccountDetails(tags) {
55
40
  } catch (err) {
56
41
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Error while getting custom account details:', err);
57
42
  }
58
- }
59
- async function loginSteps(pageDetail) {
60
- const {
61
- page
62
- } = pageDetail;
63
- if (testSetup.loginSteps && typeof testSetup.loginSteps === 'function') {
64
- return await testSetup.loginSteps(pageDetail);
65
- } else {
66
- await page.goto(process.env.domain);
67
- }
68
- }
69
- async function performDefaultPageSteps(testInfo) {
70
- if (testSetup.page && typeof testSetup.page === 'function') {
71
- await testSetup.page(testInfo);
72
- }
73
- }
74
- async function verifyPageIsLoaded(testInfo) {
75
- if (testSetup.validateLogin && typeof testSetup.validateLogin === 'function') {
76
- return await testSetup.validateLogin(testInfo);
77
- }
78
- return true;
79
- }
80
- async function executeDefaultLoginSteps(context, testInfo, testDetails, testPortalDetails) {
81
- if (!isAuthMode) {
82
- return;
83
- }
84
- try {
85
- const projectName = testInfo.project.name;
86
- if (testPortalDetails && projectName !== 'setup' && projectName !== 'cleanup') {
87
- await context.clearCookies();
88
- await (0, _auth.performLoginSteps)(testDetails, async testInfo => {
89
- return await verifyPageIsLoaded(testInfo);
90
- }, loginSteps);
91
- process.env.actorInfo = JSON.stringify(testPortalDetails);
92
- }
93
- } catch (error) {
94
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Error while executing the default login steps:', error);
95
- }
96
43
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.4.84-n18-experimental",
3
+ "version": "0.4.86-n18-experimental",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@zohodesk/testinglibrary",
9
- "version": "0.4.84-n18-experimental",
9
+ "version": "0.4.86-n18-experimental",
10
10
  "hasInstallScript": true,
11
11
  "license": "ISC",
12
12
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.4.84-n18-experimental",
3
+ "version": "0.4.86-n18-experimental",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -257,4 +257,4 @@ header {
257
257
  font-size: 1rem;
258
258
  padding: 0 0.5rem;
259
259
  }
260
- </style></head><body><div class="jesthtml-content"><header><h1 id="title">Unit Report</h1></header><div id="metadata-container"><div id="timestamp">Started: 2025-09-02 21:21:37</div><div id="summary"><div id="suite-summary"><div class="summary-total">Suites (1)</div><div class="summary-passed ">1 passed</div><div class="summary-failed summary-empty">0 failed</div><div class="summary-pending summary-empty">0 pending</div></div><div id="test-summary"><div class="summary-total">Tests (1)</div><div class="summary-passed ">1 passed</div><div class="summary-failed summary-empty">0 failed</div><div class="summary-pending summary-empty">0 pending</div></div></div></div><div id="suite-1" class="suite-container"><input id="collapsible-0" type="checkbox" class="toggle" checked="checked"/><label for="collapsible-0"><div class="suite-info"><div class="suite-path">/Users/muthu-19817/git/testing-framework/src/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js</div><div class="suite-time">0.729s</div></div></label><div class="suite-tests"><div class="test-result passed"><div class="test-info"><div class="test-suitename">executionContext</div><div class="test-title">should pass actorInfo with details from getCustomAccountDetails to use</div><div class="test-status">passed</div><div class="test-duration">0.004s</div></div></div></div></div></div></body></html>
260
+ </style></head><body><div class="jesthtml-content"><header><h1 id="title">Unit Report</h1></header><div id="metadata-container"><div id="timestamp">Started: 2025-09-03 08:57:31</div><div id="summary"><div id="suite-summary"><div class="summary-total">Suites (1)</div><div class="summary-passed ">1 passed</div><div class="summary-failed summary-empty">0 failed</div><div class="summary-pending summary-empty">0 pending</div></div><div id="test-summary"><div class="summary-total">Tests (1)</div><div class="summary-passed ">1 passed</div><div class="summary-failed summary-empty">0 failed</div><div class="summary-pending summary-empty">0 pending</div></div></div></div><div id="suite-1" class="suite-container"><input id="collapsible-0" type="checkbox" class="toggle" checked="checked"/><label for="collapsible-0"><div class="suite-info"><div class="suite-path">/Users/muthu-19817/git/testing-framework/src/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js</div><div class="suite-time">0.851s</div></div></label><div class="suite-tests"><div class="test-result passed"><div class="test-info"><div class="test-suitename">executionContext</div><div class="test-title">should pass actorInfo with details from getCustomAccountDetails to use</div><div class="test-status">passed</div><div class="test-duration">0.004s</div></div></div></div></div></div></body></html>