ff-dom 1.0.18-beta.4 → 1.0.18-beta.6

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.
package/dist/index.cdn.js CHANGED
@@ -1083,7 +1083,7 @@
1083
1083
  currentNode = currentNode.parentElement;
1084
1084
  }
1085
1085
  // Final constructed XPath
1086
- const finalXPath = xpathParts.join("");
1086
+ const finalXPath = xpathParts.join("") + nodeXpath;
1087
1087
  let count = getCountOfXPath(finalXPath, domNode, docmt);
1088
1088
  if (count === 1) {
1089
1089
  parentXpathCache.set(domNode, finalXPath); // Cache final result
@@ -2278,7 +2278,7 @@
2278
2278
  tag.remove();
2279
2279
  });
2280
2280
  }
2281
- tempDiv.innerHTML = document.body.innerHTML;
2281
+ tempDiv.innerHTML = document.body?.innerHTML;
2282
2282
  const finalLocatorsSet = new Set();
2283
2283
  let finalLocators = [];
2284
2284
  function createLocator(base, overrides = {}) {
@@ -2381,7 +2381,7 @@
2381
2381
  else if ((locator.name.includes("xpath") ||
2382
2382
  trimmedSelector.startsWith("//")) &&
2383
2383
  !locator.type.match("dynamic")) {
2384
- if (tempDiv.innerHTML) {
2384
+ if (tempDiv?.innerHTML) {
2385
2385
  const normalizedXPath = normalizeXPath(trimmedSelector);
2386
2386
  targetElement = getElementFromXPath(tempDiv, normalizedXPath);
2387
2387
  if (targetElement) {
@@ -2478,17 +2478,16 @@
2478
2478
  });
2479
2479
  });
2480
2480
  }
2481
- const fnValue = parseDOM(targetElement, document, false, true);
2482
- record.locators.forEach((loc) => {
2483
- createLocator(loc, {
2484
- name: 'xpath',
2485
- value: fnValue,
2486
- isRecorded: fnValue?.find((x) => x.value === loc.value)
2487
- ? loc.isRecorded
2488
- : "Y",
2489
- isSelfHealed: fnValue?.find((x) => x.value === loc.value)
2490
- ? loc.isSelfHealed
2491
- : "Y",
2481
+ const xpathResults = parseDOM(targetElement, document, false, true);
2482
+ xpathResults.forEach((result) => {
2483
+ const fnValue = result.value;
2484
+ record.locators.forEach((loc) => {
2485
+ createLocator(loc, {
2486
+ name: 'xpath',
2487
+ value: fnValue,
2488
+ isRecorded: loc.value === fnValue ? loc.isRecorded : 'Y',
2489
+ isSelfHealed: loc.value === fnValue ? loc.isSelfHealed : 'Y',
2490
+ });
2492
2491
  });
2493
2492
  });
2494
2493
  for (const locator of record.locators) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ff-dom",
3
- "version": "1.0.18-beta.4",
3
+ "version": "1.0.18-beta.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [
@@ -148,7 +148,7 @@ const getElementsFromHTML = (
148
148
  });
149
149
  }
150
150
 
151
- tempDiv.innerHTML = document.body.innerHTML;
151
+ tempDiv.innerHTML = document.body?.innerHTML;
152
152
  const finalLocatorsSet: Set<string> = new Set();
153
153
  let finalLocators: any[] = [];
154
154
 
@@ -289,7 +289,7 @@ const getElementsFromHTML = (
289
289
  trimmedSelector.startsWith("//")) &&
290
290
  !locator.type.match("dynamic")
291
291
  ) {
292
- if (tempDiv.innerHTML) {
292
+ if (tempDiv?.innerHTML) {
293
293
  const normalizedXPath = normalizeXPath(trimmedSelector);
294
294
  targetElement = getElementFromXPath(
295
295
  tempDiv,
@@ -167,24 +167,21 @@ const getUniqueParentXpath = (
167
167
 
168
168
  if (!reWhiteSpace.test(currentNode.textContent)) {
169
169
  xpathe = isSvg(currentNode)
170
- ? `//*[local-name()='${
171
- currentNode.tagName
172
- }' and normalize-space(.)=${escapeCharacters(
173
- getFilteredText(currentNode)
174
- )}]`
175
- : `//${
176
- currentNode.tagName || "*"
177
- }[normalize-space(.)=${escapeCharacters(
178
- getFilteredText(currentNode)
179
- )}]`;
170
+ ? `//*[local-name()='${currentNode.tagName
171
+ }' and normalize-space(.)=${escapeCharacters(
172
+ getFilteredText(currentNode)
173
+ )}]`
174
+ : `//${currentNode.tagName || "*"
175
+ }[normalize-space(.)=${escapeCharacters(
176
+ getFilteredText(currentNode)
177
+ )}]`;
180
178
  } else {
181
179
  xpathe = isSvg(currentNode)
182
- ? `//*[local-name()='${
183
- currentNode.tagName
184
- }' and .=${escapeCharacters(getFilteredText(currentNode))}]`
180
+ ? `//*[local-name()='${currentNode.tagName
181
+ }' and .=${escapeCharacters(getFilteredText(currentNode))}]`
185
182
  : `//${currentNode.tagName || "*"}[.=${escapeCharacters(
186
- getFilteredText(currentNode)
187
- )}]`;
183
+ getFilteredText(currentNode)
184
+ )}]`;
188
185
  }
189
186
 
190
187
  const othersWithAttr = checkRelativeXpathRelation(
@@ -226,12 +223,11 @@ const getUniqueParentXpath = (
226
223
 
227
224
  if (combinePattern?.length) {
228
225
  const xpathe = isSvg(currentNode)
229
- ? `//*[local-name()='${
230
- currentNode.tagName
231
- }' and ${combinePattern.join(" and ")}]`
226
+ ? `//*[local-name()='${currentNode.tagName
227
+ }' and ${combinePattern.join(" and ")}]`
232
228
  : `//${currentNode.tagName || "*"}[${combinePattern.join(
233
- " and "
234
- )}]`;
229
+ " and "
230
+ )}]`;
235
231
  const othersWithAttr = checkRelativeXpathRelation(
236
232
  xpathe,
237
233
  nodeXpath,
@@ -263,7 +259,7 @@ const getUniqueParentXpath = (
263
259
  }
264
260
 
265
261
  // Final constructed XPath
266
- const finalXPath = xpathParts.join("");
262
+ const finalXPath = xpathParts.join("") + nodeXpath;
267
263
  let count = getCountOfXPath(finalXPath, domNode, docmt);
268
264
  if (count === 1) {
269
265
  parentXpathCache.set(domNode, finalXPath); // Cache final result
@@ -392,7 +388,7 @@ const getChildRelativeXpath = (
392
388
  try {
393
389
  do {
394
390
  let uniqueAttrFound = false;
395
- for (currentNode = st.pop()!; currentNode !== null; ) {
391
+ for (currentNode = st.pop()!; currentNode !== null;) {
396
392
  for (const attr of Array.from(currentNode.attributes)) {
397
393
  if (checkBlockedAttributes(attr, currentNode, true)) {
398
394
  let attrValue = attr.nodeValue;
@@ -745,12 +741,11 @@ const addRelativeXpaths = (
745
741
  if (
746
742
  relativeXpathIndex &&
747
743
  getCountOfXPath(relativeXpathIndex, targetElemt, docmt) ===
748
- 1
744
+ 1
749
745
  ) {
750
746
  xpathData.push({
751
- key: `relative xpath by relative parent ${
752
- isIndex ? "index" : ""
753
- }`,
747
+ key: `relative xpath by relative parent ${isIndex ? "index" : ""
748
+ }`,
754
749
  value: relativeXpathIndex,
755
750
  });
756
751
  }
@@ -759,18 +754,16 @@ const addRelativeXpaths = (
759
754
  if (count < xpathDataWithIndex[0].count) {
760
755
  xpathDataWithIndex.pop();
761
756
  xpathDataWithIndex.push({
762
- key: `relative xpath by relative parent ${
763
- isIndex ? "index" : ""
764
- }`,
757
+ key: `relative xpath by relative parent ${isIndex ? "index" : ""
758
+ }`,
765
759
  value: fullRelativeXpath,
766
760
  count,
767
761
  });
768
762
  }
769
763
  } else {
770
764
  xpathDataWithIndex.push({
771
- key: `relative xpath by relative parent ${
772
- isIndex ? "index" : ""
773
- }`,
765
+ key: `relative xpath by relative parent ${isIndex ? "index" : ""
766
+ }`,
774
767
  value: fullRelativeXpath,
775
768
  count,
776
769
  });
@@ -794,9 +787,8 @@ const addRelativeXpaths = (
794
787
  relativeChildXpath.includes("text()") ||
795
788
  relativeChildXpath.includes(".="))
796
789
  ) {
797
- const fullRelativeXpath = `/${
798
- nodeXpath[i] + relativeChildXpath.substring(1)
799
- }`;
790
+ const fullRelativeXpath = `/${nodeXpath[i] + relativeChildXpath.substring(1)
791
+ }`;
800
792
  const count = getCountOfXPath(
801
793
  fullRelativeXpath,
802
794
  targetElemt,
@@ -818,12 +810,11 @@ const addRelativeXpaths = (
818
810
  if (
819
811
  relativeXpathIndex &&
820
812
  getCountOfXPath(relativeXpathIndex, targetElemt, docmt) ===
821
- 1
813
+ 1
822
814
  ) {
823
815
  xpathData.push({
824
- key: `relative xpath by relative parent ${
825
- isIndex ? "index" : ""
826
- }`,
816
+ key: `relative xpath by relative parent ${isIndex ? "index" : ""
817
+ }`,
827
818
  value: relativeXpathIndex,
828
819
  });
829
820
  }
@@ -832,18 +823,16 @@ const addRelativeXpaths = (
832
823
  if (count < xpathDataWithIndex[0].count) {
833
824
  xpathDataWithIndex.pop();
834
825
  xpathDataWithIndex.push({
835
- key: `relative xpath by relative child ${
836
- isIndex ? "index" : ""
837
- }`,
826
+ key: `relative xpath by relative child ${isIndex ? "index" : ""
827
+ }`,
838
828
  value: fullRelativeXpath,
839
829
  count,
840
830
  });
841
831
  }
842
832
  } else {
843
833
  xpathDataWithIndex.push({
844
- key: `relative xpath by relative child ${
845
- isIndex ? "index" : ""
846
- }`,
834
+ key: `relative xpath by relative child ${isIndex ? "index" : ""
835
+ }`,
847
836
  value: fullRelativeXpath,
848
837
  count,
849
838
  });