@dev-blinq/cucumber_client 1.0.1343-stage → 1.0.1344-stage

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.
@@ -676,7 +676,7 @@ class BVTRecorder {
676
676
 
677
677
  lastInputId = el.dataset.inputId;
678
678
 
679
- el.__locators = this.getLocatorsObject(el);
679
+ // el.__locators = this.getLocatorsObject(el, { maxLocators: 1 });
680
680
  }
681
681
  const role = this.PW.roleUtils.getAriaRole(el);
682
682
  const label =
@@ -790,14 +790,15 @@ class BVTRecorder {
790
790
  });
791
791
  }
792
792
 
793
- getLocatorsObject(el) {
793
+ getLocatorsObject(el, options = {}) {
794
794
  if (this.contextElement) {
795
- const result = this.locatorGenerator.toContextLocators(el, this.contextElement);
795
+ const result = this.locatorGenerator.toContextLocators(el, this.contextElement, options);
796
796
  return result;
797
797
  }
798
798
  const isRecordingText = this.#mode === "recordingText";
799
799
  return this.locatorGenerator.getElementLocators(el, {
800
800
  excludeText: isRecordingText,
801
+ ...options,
801
802
  });
802
803
  }
803
804
  addListeners() {
@@ -839,8 +840,7 @@ class BVTRecorder {
839
840
  action: action.details,
840
841
  element: this.getElementDetails(actionElement, eventName),
841
842
  isPopupCloseClick: this.isPopupCloseEvent(e),
842
- // ...this.getLocatorsObject(actionElement),
843
- ...(actionElement.__locators ?? this.getLocatorsObject(actionElement)),
843
+ // ...(actionElement.__locators ?? this.getLocatorsObject(actionElement, { maxLocators: 1 })),
844
844
  frame: this.getFrameDetails(),
845
845
  statistics: {
846
846
  time: `${performance.measure("command-received", "command-send").duration.toFixed(2)} ms`,
@@ -217,7 +217,7 @@ class LocatorGenerator {
217
217
  }
218
218
  return result;
219
219
  }
220
- toContextLocators(element, contextElement) {
220
+ toContextLocators(element, contextElement, options = {}) {
221
221
  const commonParent = this.dom_Parent.findLowestCommonAncestor([contextElement, element]);
222
222
  const climb = this.dom_Parent.getClimbCountToParent(contextElement, commonParent);
223
223
  const text = contextElement.innerText.trim();
@@ -231,6 +231,7 @@ class LocatorGenerator {
231
231
  [this.locatorStrategies.no_text]: true,
232
232
  },
233
233
  prefix,
234
+ ...options,
234
235
  });
235
236
 
236
237
  const attachContextToLocators = (locs) => {
@@ -16,7 +16,8 @@ import { unEscapeNonPrintables } from "../cucumber/utils.js";
16
16
  import { findAvailablePort } from "../utils/index.js";
17
17
  import socketLogger from "../utils/socket_logger.js";
18
18
  import { tmpdir } from "os";
19
- import { faker } from "@faker-js/faker";
19
+ import { faker } from "@faker-js/faker/locale/en_US";
20
+ import { chromium } from "playwright-core";
20
21
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
21
22
 
22
23
  const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -209,6 +210,8 @@ export class BVTRecorder {
209
210
  cmdExecutionSuccess: "BVTRecorder.cmdExecutionSuccess",
210
211
  cmdExecutionError: "BVTRecorder.cmdExecutionError",
211
212
  interceptResults: "BVTRecorder.interceptResults",
213
+ onDebugURLChange: "BVTRecorder.onDebugURLChange",
214
+ updateCommand: "BVTRecorder.updateCommand",
212
215
  };
213
216
  bindings = {
214
217
  __bvt_recordCommand: async ({ frame, page, context }, event) => {
@@ -364,6 +367,14 @@ export class BVTRecorder {
364
367
  this.web.onRestoreSaveState = (url) => {
365
368
  this._initBrowser({ url });
366
369
  };
370
+
371
+ // create a second browser for locator generation
372
+ this.backgroundBrowser = await chromium.launch({
373
+ headless: true,
374
+ });
375
+ this.backgroundContext = await this.backgroundBrowser.newContext({});
376
+ await this.backgroundContext.addInitScript({ content: this.getInitScripts(this.config) });
377
+ await this.backgroundContext.newPage();
367
378
  }
368
379
  async onClosePopup() {
369
380
  // console.log("close popups");
@@ -690,6 +701,52 @@ export class BVTRecorder {
690
701
  console.error("Error in saving screenshot: ", error);
691
702
  }
692
703
  }
704
+ async generateLocators(event) {
705
+ const snapshotDetails = event.snapshotDetails;
706
+ if (!snapshotDetails) {
707
+ throw new Error("No snapshot details found");
708
+ }
709
+ const mode = event.mode;
710
+ const inputID = event.element.inputID;
711
+
712
+ const { id, contextId, doc } = snapshotDetails;
713
+ // const selector = `[data-blinq-id="${id}"]`;
714
+ const newPage = await this.backgroundContext.newPage();
715
+ await newPage.setContent(doc);
716
+ const locatorsObj = await newPage.evaluate(
717
+ ([id, contextId, mode]) => {
718
+ const recorder = window.__bvt_Recorder;
719
+ const contextElement = document.querySelector(`[data-blinq-context-id="${contextId}"]`);
720
+ const el = document.querySelector(`[data-blinq-id="${id}"]`);
721
+ if (contextElement) {
722
+ const result = recorder.locatorGenerator.toContextLocators(el, contextElement);
723
+ return result;
724
+ }
725
+ const isRecordingText = mode === "recordingText";
726
+ return recorder.locatorGenerator.getElementLocators(el, {
727
+ excludeText: isRecordingText,
728
+ });
729
+ },
730
+ [id, contextId, mode]
731
+ );
732
+
733
+ console.log(`Generated locators: for ${inputID}: `, JSON.stringify(locatorsObj));
734
+ await newPage.close();
735
+ if (event.nestFrmLoc?.children) {
736
+ locatorsObj.nestFrmLoc = event.nestFrmLoc.children;
737
+ }
738
+
739
+ this.sendEvent(this.events.updateCommand, {
740
+ locators: {
741
+ locators: locatorsObj.locators,
742
+ nestFrmLoc: locatorsObj.nestFrmLoc,
743
+ iframe_src: !event.frame.isTop ? event.frame.url : undefined,
744
+ },
745
+ allStrategyLocators: locatorsObj.allStrategyLocators,
746
+ inputID,
747
+ });
748
+ // const
749
+ }
693
750
  async onAction(event) {
694
751
  this._updateUrlPath();
695
752
  // const locators = this.overlayLocators(event);
@@ -703,25 +760,26 @@ export class BVTRecorder {
703
760
  event.mode === "recordingHover",
704
761
  event.mode === "multiInspecting"
705
762
  ),
706
- locators: {
707
- locators: event.locators,
708
- iframe_src: !event.frame.isTop ? event.frame.url : undefined,
709
- },
710
- allStrategyLocators: event.allStrategyLocators,
763
+ // locators: {
764
+ // locators: event.locators,
765
+ // iframe_src: !event.frame.isTop ? event.frame.url : undefined,
766
+ // },
767
+ // allStrategyLocators: event.allStrategyLocators,
711
768
  url: event.frame.url,
712
769
  title: event.frame.title,
713
770
  extract: {},
714
771
  lastKnownUrlPath: this.lastKnownUrlPath,
715
772
  };
716
- if (event.nestFrmLoc?.children) {
717
- cmdEvent.locators.nestFrmLoc = event.nestFrmLoc.children;
718
- }
773
+ // if (event.nestFrmLoc?.children) {
774
+ // cmdEvent.locators.nestFrmLoc = event.nestFrmLoc.children;
775
+ // }
719
776
  // this.logger.info({ event });
720
777
  if (this.shouldTakeScreenshot) {
721
778
  await this.storeScreenshot(event);
722
779
  }
723
780
  this.sendEvent(this.events.onNewCommand, cmdEvent);
724
781
  this._updateUrlPath();
782
+ await this.generateLocators(event);
725
783
  }
726
784
  _updateUrlPath() {
727
785
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-blinq/cucumber_client",
3
- "version": "1.0.1343-stage",
3
+ "version": "1.0.1344-stage",
4
4
  "description": " ",
5
5
  "main": "bin/index.js",
6
6
  "types": "bin/index.d.ts",