MOBILE-4069 behat: Allow searching text split in different elements
parent
ebb6e393cf
commit
8f826185b6
|
@ -24,6 +24,8 @@ import { TestingBehatElementLocator, TestingBehatFindOptions } from './behat-run
|
|||
@Injectable({ providedIn: 'root' })
|
||||
export class TestingBehatDomUtilsService {
|
||||
|
||||
protected static readonly MULTI_ELEM_ALLOWED = ['P', 'SPAN', 'ION-LABEL'];
|
||||
|
||||
/**
|
||||
* Check if an element is clickable.
|
||||
*
|
||||
|
@ -154,6 +156,7 @@ export class TestingBehatDomUtilsService {
|
|||
},
|
||||
);
|
||||
|
||||
let fallbackCandidates: ElementsWithExact[] = [];
|
||||
let currentNode: Node | null = null;
|
||||
// eslint-disable-next-line no-cond-assign
|
||||
while (currentNode = treeWalker.nextNode()) {
|
||||
|
@ -202,9 +205,24 @@ export class TestingBehatDomUtilsService {
|
|||
elements.push(...this.findElementsBasedOnTextWithinWithExact(childNode, text, options));
|
||||
}
|
||||
}
|
||||
|
||||
// Allow searching text split into different elements in some cases.
|
||||
if (
|
||||
elements.length === 0 &&
|
||||
currentNode instanceof HTMLElement &&
|
||||
TestingBehatDomUtilsService.MULTI_ELEM_ALLOWED.includes(currentNode.tagName) &&
|
||||
currentNode.innerText.includes(text)
|
||||
) {
|
||||
// Only keep the child elements in the candidates list.
|
||||
fallbackCandidates = fallbackCandidates.filter(entry => !entry.element.contains(currentNode));
|
||||
fallbackCandidates.push({
|
||||
element: currentNode,
|
||||
exact: currentNode.innerText.trim() == text,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
return elements.length > 0 ? elements : fallbackCandidates;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue