@dev-blinq/cucumber_client 1.0.1178-dev → 1.0.1179-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.
@@ -387,7 +387,10 @@ const invertStableCommand = (call, elements, stepParams) => {
387
387
 
388
388
  case "snapshotValidation": {
389
389
  step.type = Types.VERIFY_PAGE_SNAPSHOT;
390
- step.parameters = extractElement(call.arguments[1]);
390
+ const inputParam = parseDataSource(call.arguments[1], stepParams);
391
+ if (inputParam.type === "literal") {
392
+ step.parameters = [inputParam.value];
393
+ }
391
394
  step.nestFrmLoc = call.arguments[0].value;
392
395
  break;
393
396
  }
@@ -429,10 +432,70 @@ const invertStableCommand = (call, elements, stepParams) => {
429
432
  return step;
430
433
  };
431
434
 
432
- // const invertApiCommand = (call) => {
435
+ /* Inspired from https://github.com/hypervillain/ast-to-literal */
436
+ // This function is not used in the current code, but it is a utility function to convert AST nodes to JSON.
437
+ const interestedLiterals = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
438
+
439
+ const toJSON = (node) => {
440
+ if (interestedLiterals.includes(node.type)) {
441
+ return node.value;
442
+ }
443
+
444
+ if (node.name === "undefined" && !node.value) {
445
+ return undefined;
446
+ }
447
+
448
+ if (node.type === "NullLiteral") {
449
+ return null;
450
+ }
451
+
452
+ if (node.type === "ObjectExpression") {
453
+ return computeProps(node.properties);
454
+ }
455
+
456
+ if (node.type === "ArrayExpression") {
457
+ return node.elements.reduce(
458
+ (acc, element) => [...acc, ...(element.type === "SpreadElement" ? toJSON(element.argument) : [toJSON(element)])],
459
+ []
460
+ );
461
+ }
462
+ };
463
+
464
+ const computeProps = (props) => {
465
+ return props.reduce((acc, prop) => {
466
+ if (prop.type === "SpreadElement") {
467
+ return {
468
+ ...acc,
469
+ ...toJSON(prop.argument),
470
+ };
471
+ } else if (prop.type === "ObjectMethod") {
472
+ const val = toJSON(prop.value);
473
+ if (val !== undefined) {
474
+ return {
475
+ ...acc,
476
+ [prop.key.name]: val,
477
+ };
478
+ }
479
+ }
480
+ return acc;
481
+ }, {});
482
+ };
433
483
 
434
- // }
435
- const invertCodeToCommand = (codeString, elements = {}, stepParams) => {
484
+ const invertApiCommand = (stepsDefinitions, codePage, stepName) => {
485
+ let apiData = null;
486
+ const step = { type: Types.API, value: null };
487
+ const apiStep = stepsDefinitions.findMatchingStep(stepName);
488
+ for (const method of codePage.methods) {
489
+ if (method.getMethodType() === "api" && method.name == apiStep.functionName) {
490
+ apiData = method.getVariableDeclerationObject("apiData");
491
+ break;
492
+ }
493
+ }
494
+ step.value = apiData;
495
+ return step;
496
+ // const apiData = toJSON(call.arguments[0]);
497
+ };
498
+ const invertCodeToCommand = (codeString, elements = {}, stepParams, stepsDefinitions, codePage, stepName) => {
436
499
  const walker = new Walker();
437
500
  const steps = [];
438
501
 
@@ -455,13 +518,12 @@ const invertCodeToCommand = (codeString, elements = {}, stepParams) => {
455
518
 
456
519
  const propName = call.callee.object.property.name;
457
520
 
458
- // if (propName === 'api') {
459
- // const step = invertApiCommand(call);
460
- // if (step) steps.push(step);
461
- // } else
462
521
  if (propName === "web" || propName === "stable") {
463
522
  const step = invertStableCommand(call, elements, stepParams);
464
523
  if (step) steps.push(step);
524
+ // } else if (propName === "api") {
525
+ // const step = invertApiCommand(stepsDefinitions, codePage, stepName);
526
+ // if (step) steps.push(step);
465
527
  } else {
466
528
  return;
467
529
  }
@@ -290,12 +290,12 @@ const _generateCodeFromCommand = (step, elements, userData) => {
290
290
  }
291
291
  case Types.VERIFY_PAGE_SNAPSHOT:
292
292
  comment = step.nestFrmLoc
293
- ? `// Verify page snapshot ${step.parameters[0]} in the frame`
293
+ ? `// Verify page snapshot ${step.parameters[0]} in the frame ${step.nestFrmLoc}`
294
294
  : `// Verify page snapshot ${step.parameters[0]}`;
295
295
  codeLines.push(escapeNonPrintables(comment));
296
296
  line = `const frameLocator = ${JSON.stringify(step.nestFrmLoc ?? null)}`;
297
297
  codeLines.push(line);
298
- line = `await context.web.snapshotValidation(frameLocator,${JSON.stringify(step.parameters[0])}, _params, ${JSON.stringify(options)}, this);`;
298
+ line = `await context.web.snapshotValidation(frameLocator, _param_0 , _params, ${JSON.stringify(options)}, this);`;
299
299
  codeLines.push(line);
300
300
  break;
301
301
  case Types.VERIFY_PAGE_CONTAINS_TEXT:
@@ -224,6 +224,16 @@ class StepsDefinitions {
224
224
  }
225
225
  }
226
226
  }
227
+ } else if (codeObj.type === "VariableDeclaration") {
228
+ if (codeObj.code.includes("context.api.")) {
229
+ codeObj.local_type = "context_api";
230
+ // set api_type to request, etc
231
+ let startIndex = codeObj.code.indexOf("context.api.") + "context.api.".length;
232
+ let endIndex = codeObj.code.indexOf("(", startIndex);
233
+ if (endIndex >= 0) {
234
+ codeObj.api_type = codeObj.code.substring(startIndex, endIndex);
235
+ }
236
+ }
227
237
  }
228
238
  }
229
239
  analyzeStepDefinitionwithStep(step) {
@@ -495,6 +495,16 @@ export class BVTRecorder {
495
495
  this.sendEvent(this.events.onGoto, { url: transition.userTypedURL });
496
496
  }
497
497
  }
498
+
499
+ async getCurrentPageTitle() {
500
+ const title = await this.page.title();
501
+ return title;
502
+ }
503
+ async getCurrentPageUrl() {
504
+ const url = await this.page.url();
505
+ return url;
506
+ }
507
+
498
508
  _addPagelisteners(context) {
499
509
  context.on("page", async (page) => {
500
510
  try {
@@ -216,6 +216,12 @@ const init = ({ envName, projectDir, roomId, TOKEN }) => {
216
216
  return { folder: snapshotFolder, files: ymlFiles };
217
217
  } else return { folder: null, files: [] };
218
218
  },
219
+ "recorderWindow.getCurrentPageTitle": async (input) => {
220
+ return await recorder.getCurrentPageTitle();
221
+ },
222
+ "recorderWindow.getCurrentPageUrl": async (input) => {
223
+ return await recorder.getCurrentPageUrl();
224
+ },
219
225
  "recorderWindow.sendAriaSnapshot": async (input) => {
220
226
  const snapshot = input?.snapshot;
221
227
  const deselect = input?.deselect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1178-dev",
3
+ "version": "1.0.1179-dev",
4
4
  "description": "",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",