Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
waitForRequests: false
});
} catch (e) {
// if it cannot be found immediately wait longer
element = await this._browser.find(selectorOrStep, {
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,
waitForRequests: false
});
} catch (e) {
// if it cannot be found immediately wait longer
export const getFindElementOptions = (
options: T
) => {
const findOptions = { ...options };
if (isNil(options.sleepMs)) {
findOptions.sleepMs = CONFIG.sleepMs;
}
if (isNil(options.timeoutMs)) {
findOptions.timeoutMs = CONFIG.timeoutMs;
}
return findOptions;
};
await new Promise(resolve => setTimeout(resolve, CONFIG.sleepMs));