(selector: unknown)
| 181 | } |
| 182 | |
| 183 | function resolveAnchor(selector: unknown): Element { |
| 184 | if (selector instanceof Element) { |
| 185 | return selector |
| 186 | } |
| 187 | if (typeof selector === 'function') { |
| 188 | return resolveAnchor((selector as () => unknown)()) |
| 189 | } |
| 190 | if (selector && typeof selector === 'object') { |
| 191 | const found = findElements(selector as LocatorTarget) |
| 192 | if (!found.length) { |
| 193 | throw botError(NO_SUCH_ELEMENT, 'No element has been found by ' + JSON.stringify(selector)) |
| 194 | } |
| 195 | return found[0] |
| 196 | } |
| 197 | throw botError(INVALID_ARGUMENT, 'Selector is of wrong type: ' + JSON.stringify(selector)) |
| 198 | } |
| 199 | |
| 200 | function makeProximityFilter(selector: unknown, test: (anchor: Rect, candidate: Rect) => boolean) { |
| 201 | return (candidate: Element): boolean => test(getClientRect(resolveAnchor(selector)), getClientRect(candidate)) |
no test coverage detected