Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const select = async (
elementHandle: ElementHandle,
value: string | null,
timeoutMs?: number
): Promise => {
logger.verbose("actions.select");
const findTimeoutMs = (isNil(timeoutMs) ? CONFIG.findTimeoutMs : timeoutMs)!;
// ensure option with desired value is loaded before selecting
await elementHandle.evaluate(
(element: HTMLSelectElement, value: string | null, timeoutMs: number) => {
const qawolf: QAWolfWeb = (window as any).qawolf;
return qawolf.select.waitForOption(element, value, timeoutMs);
},
value,
findTimeoutMs
);
await elementHandle.select(value || "");
};
this.global.waitUntil = (
booleanFn: () => boolean,
timeoutMs?: number,
sleepMs?: number
) =>
waitUntil(
booleanFn,
// default timeoutMs to CONFIG.findTimeoutMs
(isNil(timeoutMs) ? CONFIG.findTimeoutMs : timeoutMs)!,
sleepMs
);
private async beforeAction(
selectorOrStep: Selector | Step | null,
action: Action
) {
logger.verbose("Runner: beforeAction");
let element = selectorOrStep
? await this._browser.find(selectorOrStep, {
action,
timeoutMs: CONFIG.findTimeoutMs
})
: null;
if (CONFIG.sleepMs) {
logger.verbose(`Runner: beforeAction sleep ${CONFIG.sleepMs} ms`);
await sleep(CONFIG.sleepMs);
// reload the element in case it changed since the sleep
if (selectorOrStep) {
logger.verbose("Runner: beforeAction reload element after sleep");
try {
// try to find it immediately
element = await this._browser.find(selectorOrStep, {
action,
timeoutMs: 0,
await retryExecutionError(async () => {
const element = await this.beforeAction(selectorOrStep, "scroll");
await scroll(
element!,
this.getValue((selectorOrStep as Step).index, value),
CONFIG.findTimeoutMs
);
});
}