@dev-blinq/cucumber_client 1.0.1556-dev → 1.0.1557-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.
|
@@ -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) => {
|
|
@@ -17,6 +17,7 @@ import { findAvailablePort } from "../utils/index.js";
|
|
|
17
17
|
import socketLogger from "../utils/socket_logger.js";
|
|
18
18
|
import { tmpdir } from "os";
|
|
19
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,7 @@ export class BVTRecorder {
|
|
|
209
210
|
cmdExecutionError: "BVTRecorder.cmdExecutionError",
|
|
210
211
|
interceptResults: "BVTRecorder.interceptResults",
|
|
211
212
|
onDebugURLChange: "BVTRecorder.onDebugURLChange",
|
|
213
|
+
updateCommand: "BVTRecorder.updateCommand",
|
|
212
214
|
};
|
|
213
215
|
bindings = {
|
|
214
216
|
__bvt_recordCommand: async ({ frame, page, context }, event) => {
|
|
@@ -372,6 +374,14 @@ export class BVTRecorder {
|
|
|
372
374
|
this.web.onRestoreSaveState = (url) => {
|
|
373
375
|
this._initBrowser({ url });
|
|
374
376
|
};
|
|
377
|
+
|
|
378
|
+
// create a second browser for locator generation
|
|
379
|
+
this.backgroundBrowser = await chromium.launch({
|
|
380
|
+
headless: true,
|
|
381
|
+
});
|
|
382
|
+
this.backgroundContext = await this.backgroundBrowser.newContext({});
|
|
383
|
+
await this.backgroundContext.addInitScript({ content: this.getInitScripts(this.config) });
|
|
384
|
+
await this.backgroundContext.newPage();
|
|
375
385
|
}
|
|
376
386
|
async onClosePopup() {
|
|
377
387
|
// console.log("close popups");
|
|
@@ -701,6 +711,52 @@ export class BVTRecorder {
|
|
|
701
711
|
console.error("Error in saving screenshot: ", error);
|
|
702
712
|
}
|
|
703
713
|
}
|
|
714
|
+
async generateLocators(event) {
|
|
715
|
+
const snapshotDetails = event.snapshotDetails;
|
|
716
|
+
if (!snapshotDetails) {
|
|
717
|
+
throw new Error("No snapshot details found");
|
|
718
|
+
}
|
|
719
|
+
const mode = event.mode;
|
|
720
|
+
const inputID = event.element.inputID;
|
|
721
|
+
|
|
722
|
+
const { id, contextId, doc } = snapshotDetails;
|
|
723
|
+
// const selector = `[data-blinq-id="${id}"]`;
|
|
724
|
+
const newPage = await this.backgroundContext.newPage();
|
|
725
|
+
await newPage.setContent(doc);
|
|
726
|
+
const locatorsObj = await newPage.evaluate(
|
|
727
|
+
([id, contextId, mode]) => {
|
|
728
|
+
const recorder = window.__bvt_Recorder;
|
|
729
|
+
const contextElement = document.querySelector(`[data-blinq-context-id="${contextId}"]`);
|
|
730
|
+
const el = document.querySelector(`[data-blinq-id="${id}"]`);
|
|
731
|
+
if (contextElement) {
|
|
732
|
+
const result = recorder.locatorGenerator.toContextLocators(el, contextElement);
|
|
733
|
+
return result;
|
|
734
|
+
}
|
|
735
|
+
const isRecordingText = mode === "recordingText";
|
|
736
|
+
return recorder.locatorGenerator.getElementLocators(el, {
|
|
737
|
+
excludeText: isRecordingText,
|
|
738
|
+
});
|
|
739
|
+
},
|
|
740
|
+
[id, contextId, mode]
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
console.log(`Generated locators: for ${inputID}: `, JSON.stringify(locatorsObj));
|
|
744
|
+
await newPage.close();
|
|
745
|
+
if (event.nestFrmLoc?.children) {
|
|
746
|
+
locatorsObj.nestFrmLoc = event.nestFrmLoc.children;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
this.sendEvent(this.events.updateCommand, {
|
|
750
|
+
locators: {
|
|
751
|
+
locators: locatorsObj.locators,
|
|
752
|
+
nestFrmLoc: locatorsObj.nestFrmLoc,
|
|
753
|
+
iframe_src: !event.frame.isTop ? event.frame.url : undefined,
|
|
754
|
+
},
|
|
755
|
+
allStrategyLocators: locatorsObj.allStrategyLocators,
|
|
756
|
+
inputID,
|
|
757
|
+
});
|
|
758
|
+
// const
|
|
759
|
+
}
|
|
704
760
|
async onAction(event) {
|
|
705
761
|
this._updateUrlPath();
|
|
706
762
|
// const locators = this.overlayLocators(event);
|
|
@@ -714,25 +770,26 @@ export class BVTRecorder {
|
|
|
714
770
|
event.mode === "recordingHover",
|
|
715
771
|
event.mode === "multiInspecting"
|
|
716
772
|
),
|
|
717
|
-
locators: {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
},
|
|
721
|
-
allStrategyLocators: event.allStrategyLocators,
|
|
773
|
+
// locators: {
|
|
774
|
+
// locators: event.locators,
|
|
775
|
+
// iframe_src: !event.frame.isTop ? event.frame.url : undefined,
|
|
776
|
+
// },
|
|
777
|
+
// allStrategyLocators: event.allStrategyLocators,
|
|
722
778
|
url: event.frame.url,
|
|
723
779
|
title: event.frame.title,
|
|
724
780
|
extract: {},
|
|
725
781
|
lastKnownUrlPath: this.lastKnownUrlPath,
|
|
726
782
|
};
|
|
727
|
-
if (event.nestFrmLoc?.children) {
|
|
728
|
-
|
|
729
|
-
}
|
|
783
|
+
// if (event.nestFrmLoc?.children) {
|
|
784
|
+
// cmdEvent.locators.nestFrmLoc = event.nestFrmLoc.children;
|
|
785
|
+
// }
|
|
730
786
|
// this.logger.info({ event });
|
|
731
787
|
if (this.shouldTakeScreenshot) {
|
|
732
788
|
await this.storeScreenshot(event);
|
|
733
789
|
}
|
|
734
790
|
this.sendEvent(this.events.onNewCommand, cmdEvent);
|
|
735
791
|
this._updateUrlPath();
|
|
792
|
+
await this.generateLocators(event);
|
|
736
793
|
}
|
|
737
794
|
_updateUrlPath() {
|
|
738
795
|
try {
|