@dev-blinq/cucumber_client 1.0.1477-dev → 1.0.1479-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.
|
@@ -221,6 +221,8 @@ class LocatorGenerator {
|
|
|
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();
|
|
224
|
+
|
|
225
|
+
const prefix = `internal:text="${text}" >> ${this.getXPathSelector(climb)}`;
|
|
224
226
|
const result = this.getElementLocators(element, {
|
|
225
227
|
root: commonParent,
|
|
226
228
|
strategies: {
|
|
@@ -228,24 +230,13 @@ class LocatorGenerator {
|
|
|
228
230
|
[this.locatorStrategies.text]: true,
|
|
229
231
|
[this.locatorStrategies.no_text]: true,
|
|
230
232
|
},
|
|
233
|
+
prefix,
|
|
231
234
|
});
|
|
232
235
|
|
|
233
|
-
const randomToken = Math.random().toString(36).substring(2, 8);
|
|
234
|
-
commonParent.setAttribute("data-blinq--" + randomToken, "true");
|
|
235
|
-
// const contextLocators = [];
|
|
236
|
-
|
|
237
236
|
const attachContextToLocators = (locs) => {
|
|
238
237
|
locs.forEach((loc) => {
|
|
239
238
|
loc.climb = climb;
|
|
240
239
|
loc.text = text;
|
|
241
|
-
const _selector = `[data-blinq--${randomToken}]` + " >> " + this.getXPathSelector(climb) + " >> " + loc.css;
|
|
242
|
-
const elements = this.getMatchingElements(_selector, { root: window.document });
|
|
243
|
-
const index = elements.indexOf(element);
|
|
244
|
-
if (index !== -1) {
|
|
245
|
-
loc.index = index;
|
|
246
|
-
} else {
|
|
247
|
-
console.error("Invalid context locator, element not found in context locator", loc, element, contextElement);
|
|
248
|
-
}
|
|
249
240
|
});
|
|
250
241
|
};
|
|
251
242
|
const allStrategyLocators = result.allStrategyLocators;
|
|
@@ -262,6 +253,7 @@ class LocatorGenerator {
|
|
|
262
253
|
attachContextToLocators(allLocators);
|
|
263
254
|
allStrategyLocators[this.locatorStrategies.context] = allLocators;
|
|
264
255
|
allStrategyLocators.strategy = this.locatorStrategies.context;
|
|
256
|
+
result.locators = allLocators;
|
|
265
257
|
return result;
|
|
266
258
|
}
|
|
267
259
|
if (locators) {
|
|
@@ -678,7 +670,7 @@ class LocatorGenerator {
|
|
|
678
670
|
|
|
679
671
|
getUniqueLocators2(element, locatorGenerator = this.getNoTextLocators, options = {}) {
|
|
680
672
|
try {
|
|
681
|
-
const { maxLocators = 5, root = window.document.body } = options;
|
|
673
|
+
const { maxLocators = 5, root = window.document.body, prefix } = options;
|
|
682
674
|
|
|
683
675
|
if (!element) {
|
|
684
676
|
return [];
|
|
@@ -725,12 +717,13 @@ class LocatorGenerator {
|
|
|
725
717
|
|
|
726
718
|
const elementsCache = new Map();
|
|
727
719
|
|
|
728
|
-
const allAncestors = this.dom_Parent.getFullAncestorChainToRoot(element, root);
|
|
720
|
+
const allAncestors = prefix ? [element] : this.dom_Parent.getFullAncestorChainToRoot(element, root);
|
|
729
721
|
allAncestors.shift(); // remove the element itself from the ancestors
|
|
730
722
|
|
|
731
723
|
const cache = new Map();
|
|
732
724
|
const textToIgnore = this.PW.selectorUtils.elementText(cache, element).full.trim();
|
|
733
725
|
const ancestorLocators = [];
|
|
726
|
+
let uniqueAncestor = null;
|
|
734
727
|
for (const ancestor of allAncestors) {
|
|
735
728
|
const _locators = locatorGenerator(ancestor, { ...options, textToIgnore });
|
|
736
729
|
if (!_locators || !Array.isArray(_locators) || _locators.length === 0) {
|
|
@@ -743,11 +736,15 @@ class LocatorGenerator {
|
|
|
743
736
|
});
|
|
744
737
|
elementsCache.set(ancestor, _categorized);
|
|
745
738
|
if (_categorized.unique.length > 0) {
|
|
739
|
+
uniqueAncestor = {
|
|
740
|
+
element: ancestor,
|
|
741
|
+
locators: _categorized,
|
|
742
|
+
};
|
|
746
743
|
break;
|
|
747
744
|
}
|
|
748
745
|
}
|
|
749
746
|
|
|
750
|
-
const uniqueAncestor = ancestorLocators[ancestorLocators.length - 1];
|
|
747
|
+
// const uniqueAncestor = ancestorLocators[ancestorLocators.length - 1];
|
|
751
748
|
|
|
752
749
|
for (const locator of nonUnique) {
|
|
753
750
|
const selector = locator.css ?? locator.selector;
|
|
@@ -756,6 +753,27 @@ class LocatorGenerator {
|
|
|
756
753
|
console.warn(`No elements found for locator: ${selector}`);
|
|
757
754
|
continue;
|
|
758
755
|
}
|
|
756
|
+
if (!uniqueAncestor) {
|
|
757
|
+
const elements = this.getMatchingElements(selector, options);
|
|
758
|
+
if (elements.length === 1 && elements[0] === element) {
|
|
759
|
+
result.push({
|
|
760
|
+
css: selector,
|
|
761
|
+
score: locator.score,
|
|
762
|
+
priority: 1,
|
|
763
|
+
});
|
|
764
|
+
} else {
|
|
765
|
+
const index = elements.indexOf(element);
|
|
766
|
+
if (index !== -1) {
|
|
767
|
+
result.push({
|
|
768
|
+
css: selector,
|
|
769
|
+
index,
|
|
770
|
+
score: locator.score + 200,
|
|
771
|
+
priority: 2,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
759
777
|
|
|
760
778
|
for (const unique_locator of uniqueAncestor.locators.unique) {
|
|
761
779
|
const fullSelector = `${unique_locator.css} >> ${selector}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev-blinq/cucumber_client",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1479-dev",
|
|
4
4
|
"description": " ",
|
|
5
5
|
"main": "bin/index.js",
|
|
6
6
|
"types": "bin/index.d.ts",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@cucumber/tag-expressions": "^6.1.1",
|
|
40
40
|
"@dev-blinq/cucumber-js": "1.0.187-dev",
|
|
41
41
|
"@faker-js/faker": "^8.1.0",
|
|
42
|
-
"automation_model": "1.0.
|
|
42
|
+
"automation_model": "1.0.853-dev",
|
|
43
43
|
"axios": "^1.7.4",
|
|
44
44
|
"chokidar": "^3.6.0",
|
|
45
45
|
"create-require": "^1.1.1",
|