@qawolf/web
Advanced tools
Comparing version 0.7.2 to 0.7.3
export declare const getClickableAncestor: (element: HTMLElement, dataAttribute: string) => HTMLElement; | ||
export declare const getDataValue: (element: HTMLElement, dataAttribute: string | null) => string | null; | ||
export declare const isClickable: (element: HTMLElement, computedStyle: CSSStyleDeclaration) => boolean; | ||
export declare const isVisible: (element: HTMLElement, computedStyle?: CSSStyleDeclaration | undefined) => boolean; | ||
export declare const isVisible: (element: Element, computedStyle?: CSSStyleDeclaration | undefined) => boolean; |
@@ -35,8 +35,11 @@ "use strict"; | ||
exports.isVisible = (element, computedStyle) => { | ||
if (element.offsetWidth <= 0 || element.offsetHeight <= 0) | ||
const htmlElement = element; | ||
if (htmlElement.offsetWidth <= 0 || htmlElement.offsetHeight <= 0) { | ||
return false; | ||
if (computedStyle && computedStyle.visibility === "hidden") | ||
} | ||
if (computedStyle && computedStyle.visibility === "hidden") { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
//# sourceMappingURL=element.js.map |
import { DocSelector, FindElementOptions, Selector } from "@qawolf/types"; | ||
import { DocMatch } from "./compare"; | ||
declare type ElementMatch = { | ||
element: HTMLElement; | ||
element: Element; | ||
match: DocMatch; | ||
}; | ||
export declare const findHtml: (selector: Selector, options: FindElementOptions) => Promise<HTMLElement | null>; | ||
export declare const matchElements: (elements: HTMLElement[], target: DocSelector, dataAttribute?: string | undefined) => ElementMatch[]; | ||
export declare const findHtml: (selector: Selector, options: FindElementOptions) => Promise<Element | null>; | ||
export declare const matchElements: (elements: Element[], target: DocSelector, dataAttribute?: string | undefined) => ElementMatch[]; | ||
export {}; |
@@ -24,2 +24,4 @@ "use strict"; | ||
const element = elements[i]; | ||
if (!element.innerText) | ||
continue; | ||
if (element.innerText.includes(selector.text) && | ||
@@ -26,0 +28,0 @@ (!match || match.innerText.length > element.innerText.length)) { |
@@ -11,6 +11,6 @@ import { Action, DocSelector } from "@qawolf/types"; | ||
}; | ||
export declare const queryActionElements: (action?: "click" | "type" | "scroll" | "select" | undefined) => HTMLElement[]; | ||
export declare const queryDataElements: ({ action, dataAttribute, dataValue }: QueryDataElementsOptions) => HTMLElement[]; | ||
export declare const queryElements: (selector: DocSelector, { action, dataAttribute }: QueryElementsOptions) => HTMLElement[]; | ||
export declare const queryVisibleElements: (selector: string) => HTMLElement[]; | ||
export declare const queryActionElements: (action?: "click" | "type" | "scroll" | "select" | undefined) => Element[]; | ||
export declare const queryDataElements: ({ action, dataAttribute, dataValue }: QueryDataElementsOptions) => Element[]; | ||
export declare const queryElements: (selector: DocSelector, { action, dataAttribute }: QueryElementsOptions) => Element[]; | ||
export declare const queryVisibleElements: (selector: string) => Element[]; | ||
export {}; |
@@ -20,3 +20,3 @@ import * as element from "./element"; | ||
declare const decodeHtml: (text?: string) => string, isNil: (value?: any) => boolean; | ||
declare const sleep: (milliseconds: number) => Promise<void>, waitFor: <T>(valueFn: () => T | null, timeoutMs: number, sleepMs?: number) => Promise<T | null>, waitUntil: (booleanFn: () => boolean | Promise<boolean>, timeoutMs: number, sleepMs?: number) => Promise<void>; | ||
declare const sleep: (milliseconds: number) => Promise<void>, waitFor: <T>(valueFunction: () => T | null, timeoutMs: number, sleepMs?: number) => Promise<T | null>, waitUntil: (predicate: () => boolean | Promise<boolean>, timeoutMs: number, sleepMs?: number) => Promise<void>; | ||
export { compareAttributes, compareContent, compareDoc, decodeHtml, htmlSelectorToDocSelector, htmlToDoc, isKeyEvent, isNil, isPasteEvent, isTypeEvent, matchDocSelector, serializeDocSelector, serializeStep, sleep, waitFor, waitUntil }; | ||
@@ -23,0 +23,0 @@ declare const webExports: { |
@@ -11,5 +11,7 @@ var qawolf = (function (exports) { | ||
}; | ||
var buildXpath = function (element) { | ||
if (!element || element.nodeType !== 1) | ||
var buildXpath = function (node) { | ||
// only build xpaths for elements | ||
if (!node || node.nodeType !== 1) | ||
return ""; | ||
var element = node; | ||
if (element.id) { | ||
@@ -33,4 +35,4 @@ // xpath has no way to escape quotes so use the opposite | ||
}; | ||
var getXpath = function (element) { | ||
var result = buildXpath(element); | ||
var getXpath = function (node) { | ||
var result = buildXpath(node); | ||
return result | ||
@@ -97,6 +99,9 @@ .replace("svg", "*[name()='svg']") | ||
var isVisible = function (element, computedStyle) { | ||
if (element.offsetWidth <= 0 || element.offsetHeight <= 0) | ||
var htmlElement = element; | ||
if (htmlElement.offsetWidth <= 0 || htmlElement.offsetHeight <= 0) { | ||
return false; | ||
if (computedStyle && computedStyle.visibility === "hidden") | ||
} | ||
if (computedStyle && computedStyle.visibility === "hidden") { | ||
return false; | ||
} | ||
return true; | ||
@@ -340,3 +345,3 @@ }; | ||
}; | ||
var waitFor = function (valueFn, timeoutMs, sleepMs) { | ||
var waitFor = function (valueFunction, timeoutMs, sleepMs) { | ||
if (sleepMs === void 0) { sleepMs = 500; } | ||
@@ -351,3 +356,3 @@ return __awaiter(void 0, void 0, Promise, function () { | ||
case 1: | ||
value = valueFn(); | ||
value = valueFunction(); | ||
if (value) | ||
@@ -367,3 +372,3 @@ return [2 /*return*/, value]; | ||
}; | ||
var waitUntil = function (booleanFn, timeoutMs, sleepMs) { | ||
var waitUntil = function (predicate, timeoutMs, sleepMs) { | ||
if (sleepMs === void 0) { sleepMs = 500; } | ||
@@ -377,3 +382,3 @@ return __awaiter(void 0, void 0, Promise, function () { | ||
_a.label = 1; | ||
case 1: return [4 /*yield*/, booleanFn()]; | ||
case 1: return [4 /*yield*/, predicate()]; | ||
case 2: | ||
@@ -862,2 +867,5 @@ conditionMet = _a.sent(); | ||
var element = elements[i]; | ||
// skip non-HTML elements | ||
if (!element.innerText) | ||
continue; | ||
if ( | ||
@@ -864,0 +872,0 @@ // check the innerText includes the selector.text |
export declare const sleep: (milliseconds: number) => Promise<void>; | ||
export declare const waitFor: <T>(valueFn: () => T | null, timeoutMs: number, sleepMs?: number) => Promise<T | null>; | ||
export declare const waitUntil: (booleanFn: () => boolean | Promise<boolean>, timeoutMs: number, sleepMs?: number) => Promise<void>; | ||
export declare const waitFor: <T>(valueFunction: () => T | null, timeoutMs: number, sleepMs?: number) => Promise<T | null>; | ||
export declare const waitUntil: (predicate: () => boolean | Promise<boolean>, timeoutMs: number, sleepMs?: number) => Promise<void>; |
@@ -15,6 +15,6 @@ "use strict"; | ||
}; | ||
exports.waitFor = (valueFn, timeoutMs, sleepMs = 500) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.waitFor = (valueFunction, timeoutMs, sleepMs = 500) => __awaiter(void 0, void 0, void 0, function* () { | ||
const startTime = Date.now(); | ||
do { | ||
const value = valueFn(); | ||
const value = valueFunction(); | ||
if (value) | ||
@@ -26,6 +26,6 @@ return value; | ||
}); | ||
exports.waitUntil = (booleanFn, timeoutMs, sleepMs = 500) => __awaiter(void 0, void 0, void 0, function* () { | ||
exports.waitUntil = (predicate, timeoutMs, sleepMs = 500) => __awaiter(void 0, void 0, void 0, function* () { | ||
const startTime = Date.now(); | ||
do { | ||
const conditionMet = yield booleanFn(); | ||
const conditionMet = yield predicate(); | ||
if (conditionMet) | ||
@@ -32,0 +32,0 @@ return; |
export declare const findElementByXpath: (xpath: string) => HTMLElement | null; | ||
export declare const getXpath: (element: Element) => string; | ||
export declare const getXpath: (node: Node) => string; | ||
export declare const isXpathEqual: (xpathA?: string | null | undefined, xpathB?: string | null | undefined) => boolean; |
@@ -10,5 +10,6 @@ "use strict"; | ||
}; | ||
const buildXpath = (element) => { | ||
if (!element || element.nodeType !== 1) | ||
const buildXpath = (node) => { | ||
if (!node || node.nodeType !== 1) | ||
return ""; | ||
const element = node; | ||
if (element.id) { | ||
@@ -30,4 +31,4 @@ const quote = element.id.includes(`'`) ? `"` : `'`; | ||
}; | ||
exports.getXpath = (element) => { | ||
const result = buildXpath(element); | ||
exports.getXpath = (node) => { | ||
const result = buildXpath(node); | ||
return result | ||
@@ -34,0 +35,0 @@ .replace("svg", "*[name()='svg']") |
{ | ||
"name": "@qawolf/web", | ||
"description": "qawolf web library", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"license": "BSD-3.0", | ||
@@ -36,3 +36,3 @@ "main": "./lib/index.js", | ||
}, | ||
"gitHead": "2fa632a9eea4ac15fbbdac5889a3040ad53b79c5" | ||
"gitHead": "37c507373ee226bf39ebf7c04a0d29582e76e0ef" | ||
} |
@@ -72,10 +72,15 @@ import { getXpath } from "./xpath"; | ||
export const isVisible = ( | ||
element: HTMLElement, | ||
element: Element, | ||
computedStyle?: CSSStyleDeclaration | ||
): boolean => { | ||
if (element.offsetWidth <= 0 || element.offsetHeight <= 0) return false; | ||
const htmlElement = element as HTMLElement; | ||
if (htmlElement.offsetWidth <= 0 || htmlElement.offsetHeight <= 0) { | ||
return false; | ||
} | ||
if (computedStyle && computedStyle.visibility === "hidden") return false; | ||
if (computedStyle && computedStyle.visibility === "hidden") { | ||
return false; | ||
} | ||
return true; | ||
}; |
@@ -9,3 +9,3 @@ import { DocSelector, FindElementOptions, Selector } from "@qawolf/types"; | ||
type ElementMatch = { | ||
element: HTMLElement; | ||
element: Element; | ||
match: DocMatch; | ||
@@ -90,3 +90,3 @@ }; | ||
export const matchElements = ( | ||
elements: HTMLElement[], | ||
elements: Element[], | ||
target: DocSelector, | ||
@@ -93,0 +93,0 @@ dataAttribute?: string |
import { FindElementOptions, Selector } from "@qawolf/types"; | ||
import { cleanText } from "../lang"; | ||
import { queryActionElements } from "./query"; | ||
@@ -24,2 +23,5 @@ import { waitFor } from "../wait"; | ||
// skip non-HTML elements | ||
if (!element.innerText) continue; | ||
if ( | ||
@@ -26,0 +28,0 @@ // check the innerText includes the selector.text |
@@ -15,3 +15,3 @@ import { Action, DocSelector } from "@qawolf/types"; | ||
export const queryActionElements = (action?: Action): HTMLElement[] => { | ||
export const queryActionElements = (action?: Action): Element[] => { | ||
const selector = | ||
@@ -27,3 +27,3 @@ action === "type" ? "input,select,textarea,[contenteditable='true']" : "*"; | ||
dataValue | ||
}: QueryDataElementsOptions): HTMLElement[] => { | ||
}: QueryDataElementsOptions): Element[] => { | ||
let dataSelector = `[${dataAttribute}='${dataValue}']`; | ||
@@ -57,6 +57,6 @@ if (action === "type") { | ||
export const queryVisibleElements = (selector: string): HTMLElement[] => { | ||
export const queryVisibleElements = (selector: string): Element[] => { | ||
const elements = document.querySelectorAll(selector); | ||
const visibleElements: HTMLElement[] = []; | ||
const visibleElements: Element[] = []; | ||
@@ -66,4 +66,4 @@ for (let i = 0; i < elements.length; i++) { | ||
// that for every element would be very expensive | ||
if (isVisible(elements[i] as HTMLElement)) { | ||
visibleElements.push(elements[i] as HTMLElement); | ||
if (isVisible(elements[i])) { | ||
visibleElements.push(elements[i]); | ||
} | ||
@@ -70,0 +70,0 @@ } |
@@ -6,3 +6,3 @@ export const sleep = (milliseconds: number): Promise<void> => { | ||
export const waitFor = async <T>( | ||
valueFn: () => T | null, | ||
valueFunction: () => T | null, | ||
timeoutMs: number, | ||
@@ -14,3 +14,3 @@ sleepMs: number = 500 | ||
do { | ||
const value = valueFn(); | ||
const value = valueFunction(); | ||
if (value) return value; | ||
@@ -25,3 +25,3 @@ | ||
export const waitUntil = async ( | ||
booleanFn: () => boolean | Promise<boolean>, | ||
predicate: () => boolean | Promise<boolean>, | ||
timeoutMs: number, | ||
@@ -33,3 +33,3 @@ sleepMs: number = 500 | ||
do { | ||
const conditionMet = await booleanFn(); | ||
const conditionMet = await predicate(); | ||
if (conditionMet) return; | ||
@@ -36,0 +36,0 @@ |
@@ -17,5 +17,7 @@ export const findElementByXpath = (xpath: string): HTMLElement | null => { | ||
const buildXpath = (element: Element): string => { | ||
if (!element || element.nodeType !== 1) return ""; | ||
const buildXpath = (node: Node | null): string => { | ||
// only build xpaths for elements | ||
if (!node || node.nodeType !== 1) return ""; | ||
const element = node as Element; | ||
if (element.id) { | ||
@@ -34,3 +36,3 @@ // xpath has no way to escape quotes so use the opposite | ||
const result = | ||
buildXpath(element.parentNode as Element) + | ||
buildXpath(element.parentNode) + | ||
"/" + | ||
@@ -45,4 +47,4 @@ element.tagName.toLowerCase() + | ||
export const getXpath = (element: Element): string => { | ||
const result = buildXpath(element); | ||
export const getXpath = (node: Node): string => { | ||
const result = buildXpath(node); | ||
@@ -49,0 +51,0 @@ return result |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
144042
3040