@dev-blinq/cucumber_client 1.0.1710-dev → 1.0.1712-dev

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.
@@ -1,5 +1,9 @@
1
1
  import { Types } from "../recording.js";
2
2
  import Walker from "node-source-walk";
3
+ /**
4
+ * @typedef {import("../types/locators").Locator} Locator
5
+ * @typedef {import("../types/locators").LocatorBundle} LocatorBundle
6
+ */
3
7
 
4
8
  const extractElementIdentifier = (node) => {
5
9
  // Check for elements["someIdentifier"] pattern
@@ -87,29 +91,33 @@ const parseDataSource = (paramNode, stepParams) => {
87
91
  throw new Error("Unknown parameter type");
88
92
  };
89
93
 
90
-
91
94
  const parseOptions = (optionsNode) => {
92
95
  const properties = optionsNode.properties;
93
- const options = {}
96
+ const options = {};
94
97
  for (const prop of properties) {
95
98
  let key = "";
96
- if (prop.key.type === 'Identifier') {
99
+ if (prop.key.type === "Identifier") {
97
100
  key = prop.key.name;
98
- } else if (prop.key.type === 'StringLiteral') {
101
+ } else if (prop.key.type === "StringLiteral") {
99
102
  key = prop.key.value;
100
103
  }
101
- if (key === 'context') continue;
104
+ if (key === "context") continue;
102
105
  options[key] = prop.value.value;
103
106
  }
104
107
  return options;
105
- }
108
+ };
106
109
 
107
110
  const parseOptionsFromCallNode = (call, index) => {
108
111
  if (call.arguments[index] && call.arguments[index].type === "ObjectExpression") {
109
112
  return parseOptions(call.arguments[index]);
110
113
  }
111
- return null
112
- }
114
+ return null;
115
+ };
116
+ /**
117
+ * @param {any} call
118
+ * @param {Record<string, { locators?: Locator[] | LocatorBundle }>} elements
119
+ * @param {any[]} stepParams
120
+ */
113
121
  const invertStableCommand = (call, elements, stepParams) => {
114
122
  const methodName = call.callee.property.name;
115
123
  const step = { type: null, parameters: [], element: null, locators: null };
@@ -388,7 +396,7 @@ const invertStableCommand = (call, elements, stepParams) => {
388
396
  step.type = Types.CHECK;
389
397
  step.element = extractElement(call.arguments[0]);
390
398
  step.check = call.arguments[1].value;
391
- ///
399
+ ///
392
400
  step.options = parseOptionsFromCallNode(call, 3);
393
401
  break;
394
402
 
@@ -596,13 +604,15 @@ const invertStableCommand = (call, elements, stepParams) => {
596
604
 
597
605
  // Set locators if element exists
598
606
  if (step.element && elements[step.element.key]) {
599
- step.locators = elements[step.element.key];
607
+ /** @type {LocatorBundle | Locator[] | undefined} */
608
+ const locBundle = elements[step.element.key]?.locators;
609
+ step.locators = locBundle;
600
610
  }
601
611
 
602
612
  if (step.type === Types.CLICK) {
603
613
  // handle click with parametric locators
604
614
  // check if locators are parametric , i.e. contains `{variable}`
605
- if (step.locators && step.locators.locators && Array.isArray(step.locators.locators)) {
615
+ if (step.locators && !Array.isArray(step.locators) && Array.isArray(step.locators.locators)) {
606
616
  let hasParametricLocators = false;
607
617
  let variable = "";
608
618
  const regex = /{([^}]+)}/g;
@@ -12,6 +12,10 @@ async function verify_the_opportunity_name_was_created(_name) {
12
12
  */
13
13
 
14
14
  import strip from "strip-comments";
15
+ /**
16
+ * @typedef {import("../types/locators").Locator} Locator
17
+ * @typedef {import("../types/locators").LocatorBundle} LocatorBundle
18
+ */
15
19
 
16
20
  function generateSignature(page, functionName) {
17
21
  let functionCode = null;
@@ -1,4 +1,8 @@
1
1
  import fs from "fs";
2
+ /**
3
+ * @typedef {import("../types/locators").Locator} Locator
4
+ * @typedef {import("../types/locators").LocatorBundle} LocatorBundle
5
+ */
2
6
 
3
7
  import { Project } from "../project.js";
4
8
  import { generateCode } from "./playwright_codeget.js";
@@ -567,11 +567,16 @@ export class CodePage {
567
567
  if (!element || !element.locators)
568
568
  return element;
569
569
  const clone = JSON.parse(JSON.stringify(element));
570
- for (let i = 0; i < (clone.locators?.length ?? 0); i++) {
571
- const locator = clone.locators[i];
572
- if (locator.score)
573
- delete locator.score;
574
- }
570
+ const locatorsArray = Array.isArray(clone.locators)
571
+ ? clone.locators
572
+ : (clone.locators.locators ?? []);
573
+ for (let i = 0; i < locatorsArray.length; i++) {
574
+ if (locatorsArray[i].score)
575
+ delete locatorsArray[i].score;
576
+ }
577
+ clone.locators = Array.isArray(clone.locators)
578
+ ? locatorsArray
579
+ : { ...clone.locators, locators: locatorsArray };
575
580
  return clone;
576
581
  }
577
582
  insertElements(elements) {
@@ -114,6 +114,10 @@ function excludeKey(obj, keyToRemove) {
114
114
  const { [keyToRemove]: _, ...rest } = obj;
115
115
  return rest;
116
116
  }
117
+ /**
118
+ * Split locators by strategy
119
+ * @param {import("../types/locators").LocatorBundle} locators
120
+ */
117
121
  const splitToLocatorsGroups = (locators) => {
118
122
  const no_text = locators.locators.filter((locator) => locator.mode === "NO_TEXT");
119
123
  const ignore_digit = locators.locators.filter((locator) => locator.mode === "IGNORE_DIGIT");
@@ -135,7 +139,7 @@ const splitToLocatorsGroups = (locators) => {
135
139
 
136
140
  const serializeOptions = (options, context) => {
137
141
  if (!options) return "null";
138
- if (typeof options !== 'object') return "null";
142
+ if (typeof options !== "object") return "null";
139
143
  if (Array.isArray(options)) return "null";
140
144
  let result = "{ ";
141
145
  if (context) result += `"context": ${context}, `;
@@ -144,7 +148,7 @@ const serializeOptions = (options, context) => {
144
148
  }
145
149
  result += " }";
146
150
  return result;
147
- }
151
+ };
148
152
 
149
153
  const _generateCodeFromCommand = (step, elements, userData) => {
150
154
  let elementsChanged = false;
@@ -380,21 +384,21 @@ const _generateCodeFromCommand = (step, elements, userData) => {
380
384
  }
381
385
  // let options = "null";
382
386
  if (step.regex !== "") {
383
- options = options ?? {}
387
+ options = options ?? {};
384
388
  options = {
385
389
  ...options,
386
390
  regex: step.regex,
387
- trimSpaces: step.trimSpaces
388
- } // `{regex: ${JSON.stringify(step.regex)},trimSpaces: ${step.trimSpaces}}`;
391
+ trimSpaces: step.trimSpaces,
392
+ }; // `{regex: ${JSON.stringify(step.regex)},trimSpaces: ${step.trimSpaces}}`;
389
393
  } else if (step.trimSpaces) {
390
- options = options ?? {}
394
+ options = options ?? {};
391
395
  options = {
392
396
  ...options,
393
- trimSpaces: step.trimSpaces
394
- }
397
+ trimSpaces: step.trimSpaces,
398
+ };
395
399
  // options = `{trimSpaces: ${step.trimSpaces}}`;
396
400
  } else {
397
- options = null//"null";
401
+ options = null; //"null";
398
402
  }
399
403
  line = `await context.web.extractAttribute(elements["${elementIdentifier}"], "${attribute}", ${input}, _params, ${serializeOptions(options)}, this);`;
400
404
 
@@ -413,21 +417,21 @@ const _generateCodeFromCommand = (step, elements, userData) => {
413
417
  input = "_" + step.dataKey;
414
418
  }
415
419
  if (step.regex !== "") {
416
- options = options ?? {}
420
+ options = options ?? {};
417
421
  options = {
418
422
  ...options,
419
423
  regex: step.regex,
420
- trimSpaces: step.trimSpaces
421
- } // `{regex: ${JSON.stringify(step.regex)},trimSpaces: ${step.trimSpaces}}`;
424
+ trimSpaces: step.trimSpaces,
425
+ }; // `{regex: ${JSON.stringify(step.regex)},trimSpaces: ${step.trimSpaces}}`;
422
426
  } else if (step.trimSpaces) {
423
- options = options ?? {}
427
+ options = options ?? {};
424
428
  options = {
425
429
  ...options,
426
- trimSpaces: step.trimSpaces
427
- }
430
+ trimSpaces: step.trimSpaces,
431
+ };
428
432
  // options = `{trimSpaces: ${step.trimSpaces}}`;
429
433
  } else {
430
- options = null//"null";
434
+ options = null; //"null";
431
435
  }
432
436
  line = `await context.web.extractProperty(elements["${elementIdentifier}"], "${property}", ${input}, _params, ${serializeOptions(options)}, this);`;
433
437
 
@@ -777,7 +781,6 @@ const _generateCodeFromCommand = (step, elements, userData) => {
777
781
  break;
778
782
  }
779
783
 
780
-
781
784
  case Types.CLICK_SIMPLE:
782
785
  case Types.FILL_SIMPLE:
783
786
  // no code need to be added