@dev-blinq/cucumber_client 1.0.1472-dev → 1.0.1474-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.
|
@@ -790,22 +790,7 @@ class BVTRecorder {
|
|
|
790
790
|
|
|
791
791
|
getLocatorsObject(el) {
|
|
792
792
|
if (this.contextElement) {
|
|
793
|
-
const
|
|
794
|
-
const contextEl = this.contextElement;
|
|
795
|
-
// const { climb, commonParent } = window.getCommonParent(contextEl, el);
|
|
796
|
-
const commonParent = this.locatorGenerator.dom_Parent.findLowestCommonAncestor([contextEl, el]);
|
|
797
|
-
const climb = this.locatorGenerator.dom_Parent.getClimbCountToParent(contextEl, commonParent);
|
|
798
|
-
const result = this.locatorGenerator.getElementLocators(el, {
|
|
799
|
-
excludeText: true,
|
|
800
|
-
root: commonParent,
|
|
801
|
-
});
|
|
802
|
-
result.locators.forEach((locator) => {
|
|
803
|
-
locator.text = text;
|
|
804
|
-
locator.climb = climb;
|
|
805
|
-
});
|
|
806
|
-
result.allStrategyLocators.context = result.locators;
|
|
807
|
-
result.allStrategyLocators.strategy = "context";
|
|
808
|
-
result.allStrategyLocators.no_text = [];
|
|
793
|
+
const result = this.locatorGenerator.toContextLocators(el, this.contextElement);
|
|
809
794
|
return result;
|
|
810
795
|
}
|
|
811
796
|
const isRecordingText = this.#mode === "recordingText";
|
|
@@ -217,6 +217,59 @@ class LocatorGenerator {
|
|
|
217
217
|
}
|
|
218
218
|
return result;
|
|
219
219
|
}
|
|
220
|
+
toContextLocators(element, contextElement) {
|
|
221
|
+
const commonParent = this.dom_Parent.findLowestCommonAncestor([contextElement, element]);
|
|
222
|
+
const climb = this.dom_Parent.getClimbCountToParent(contextElement, commonParent);
|
|
223
|
+
const text = contextElement.innerText.trim();
|
|
224
|
+
const result = this.getElementLocators(element, {
|
|
225
|
+
root: commonParent,
|
|
226
|
+
strategies: {
|
|
227
|
+
[this.locatorStrategies.custom]: true,
|
|
228
|
+
[this.locatorStrategies.text]: true,
|
|
229
|
+
[this.locatorStrategies.no_text]: true,
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const randomToken = Math.random().toString(36).substring(2, 8);
|
|
234
|
+
commonParent.setAttribute("data-blinq--" + randomToken, "true");
|
|
235
|
+
// const contextLocators = [];
|
|
236
|
+
|
|
237
|
+
const attachContextToLocators = (locs) => {
|
|
238
|
+
locs.forEach((loc) => {
|
|
239
|
+
loc.climb = climb;
|
|
240
|
+
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
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const allStrategyLocators = result.allStrategyLocators;
|
|
252
|
+
const locators = result.locators;
|
|
253
|
+
if (allStrategyLocators) {
|
|
254
|
+
const allLocators = [];
|
|
255
|
+
for (const strategy in allStrategyLocators) {
|
|
256
|
+
if (strategy === "strategy") continue;
|
|
257
|
+
const locators = allStrategyLocators[strategy];
|
|
258
|
+
if (locators.length === 0) continue;
|
|
259
|
+
allLocators.push(...locators);
|
|
260
|
+
allStrategyLocators[strategy] = [];
|
|
261
|
+
}
|
|
262
|
+
attachContextToLocators(allLocators);
|
|
263
|
+
allStrategyLocators[this.locatorStrategies.context] = allLocators;
|
|
264
|
+
allStrategyLocators.strategy = this.locatorStrategies.context;
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
if (locators) {
|
|
268
|
+
attachContextToLocators(locators);
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
220
273
|
getContextLocators(element, locators) {
|
|
221
274
|
if (!locators || !Array.isArray(locators)) {
|
|
222
275
|
console.error("Locators must be an array");
|
|
@@ -743,7 +796,17 @@ class LocatorGenerator {
|
|
|
743
796
|
}
|
|
744
797
|
getElementLocators(element, options = {}) {
|
|
745
798
|
try {
|
|
746
|
-
const {
|
|
799
|
+
const {
|
|
800
|
+
excludeText = false,
|
|
801
|
+
strategies = {
|
|
802
|
+
[this.locatorStrategies.custom]: true,
|
|
803
|
+
[this.locatorStrategies.context]: true,
|
|
804
|
+
[this.locatorStrategies.text]: true,
|
|
805
|
+
[this.locatorStrategies.text_with_index]: true,
|
|
806
|
+
[this.locatorStrategies.digitIgnore]: true,
|
|
807
|
+
[this.locatorStrategies.no_text]: true,
|
|
808
|
+
},
|
|
809
|
+
} = options;
|
|
747
810
|
|
|
748
811
|
const allStrategyLocators = {
|
|
749
812
|
[this.locatorStrategies.custom]: [],
|
|
@@ -753,7 +816,12 @@ class LocatorGenerator {
|
|
|
753
816
|
[this.locatorStrategies.digitIgnore]: [],
|
|
754
817
|
[this.locatorStrategies.no_text]: [],
|
|
755
818
|
};
|
|
756
|
-
if (
|
|
819
|
+
if (
|
|
820
|
+
strategies[this.locatorStrategies.custom] &&
|
|
821
|
+
this.options?.customAttributes &&
|
|
822
|
+
Array.isArray(this.options.customAttributes) &&
|
|
823
|
+
this.options.customAttributes.length > 0
|
|
824
|
+
) {
|
|
757
825
|
console.groupCollapsed("Generating Custom locators for element:", element);
|
|
758
826
|
const customLocators = this.getUniqueLocators(element, this.getCustomLocators.bind(this), options);
|
|
759
827
|
if (customLocators.length > 0) {
|
|
@@ -762,43 +830,53 @@ class LocatorGenerator {
|
|
|
762
830
|
}
|
|
763
831
|
console.groupEnd();
|
|
764
832
|
if (!excludeText) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
console.groupEnd();
|
|
768
|
-
if (basicLocators.length > 0) {
|
|
769
|
-
allStrategyLocators[this.locatorStrategies.text] = basicLocators;
|
|
770
|
-
}
|
|
833
|
+
if (strategies[this.locatorStrategies.text]) {
|
|
834
|
+
console.groupCollapsed("Generating Text locators for element:", element);
|
|
771
835
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
836
|
+
const basicLocators = this.getUniqueLocators(element, this.getTextLocators.bind(this), options);
|
|
837
|
+
console.groupEnd();
|
|
838
|
+
if (basicLocators.length > 0) {
|
|
839
|
+
allStrategyLocators[this.locatorStrategies.text] = basicLocators;
|
|
840
|
+
}
|
|
841
|
+
if (strategies[this.locatorStrategies.text_with_index]) {
|
|
842
|
+
const textWithIndexLocators = this.getTextwithIndexLocators(basicLocators);
|
|
843
|
+
if (textWithIndexLocators.length > 0) {
|
|
844
|
+
allStrategyLocators[this.locatorStrategies.text_with_index] = textWithIndexLocators;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (strategies[this.locatorStrategies.digitIgnore]) {
|
|
848
|
+
const digitIgnoreLocators = this.getDigitIgnoreLocators(element, basicLocators);
|
|
849
|
+
if (digitIgnoreLocators.length > 0) {
|
|
850
|
+
allStrategyLocators[this.locatorStrategies.digitIgnore] = digitIgnoreLocators;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (strategies[this.locatorStrategies.context]) {
|
|
854
|
+
const contextLocators = this.getContextLocators(element, basicLocators);
|
|
855
|
+
if (contextLocators.length > 0) {
|
|
856
|
+
allStrategyLocators[this.locatorStrategies.context] = contextLocators;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
783
859
|
}
|
|
784
860
|
}
|
|
785
|
-
|
|
786
|
-
|
|
861
|
+
if (strategies[this.locatorStrategies.no_text]) {
|
|
862
|
+
console.groupCollapsed("Generating No Text locators for element:", element);
|
|
863
|
+
const noTextLocators = this.getUniqueLocators(element, this.getNoTextLocators.bind(this), options);
|
|
787
864
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
865
|
+
if (noTextLocators.length > 0) {
|
|
866
|
+
allStrategyLocators[this.locatorStrategies.no_text] = noTextLocators;
|
|
867
|
+
} else {
|
|
868
|
+
const _locators = [];
|
|
869
|
+
_locators.push({
|
|
870
|
+
css: this.generateUniqueCSSSelector(element, options),
|
|
871
|
+
score: 500,
|
|
872
|
+
priority: 3,
|
|
873
|
+
});
|
|
874
|
+
if (_locators.length > 0) {
|
|
875
|
+
allStrategyLocators[this.locatorStrategies.no_text] = _locators;
|
|
876
|
+
}
|
|
799
877
|
}
|
|
878
|
+
console.groupEnd();
|
|
800
879
|
}
|
|
801
|
-
console.groupEnd();
|
|
802
880
|
|
|
803
881
|
let bestStrategy = this.getBestStrategy(allStrategyLocators);
|
|
804
882
|
if (!bestStrategy) {
|
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.1474-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.850-dev",
|
|
43
43
|
"axios": "^1.7.4",
|
|
44
44
|
"chokidar": "^3.6.0",
|
|
45
45
|
"create-require": "^1.1.1",
|