Saltar al contenido principal

Servicio de Biblioteca de condiciones esperadas útiles

wdio-wait-for es un paquete de terceros, para más información, consulte GitHub | npm

wdio-wait-for es una biblioteca de Node.js para WebdriverIO que proporciona un conjunto de condiciones comunes que ofrecen funcionalidades para esperar ciertas condiciones hasta que una tarea definida se complete.

Instalación​

Para usar wdio-wait-for en tu proyecto, ejecuta:

npm i -D wdio-wait-for

Si usas Yarn, ejecuta:

yarn add --dev wdio-wait-for

API​

Ejemplos​

Importación​

CommonJS​

Si estás usando WebdriverIO v7 o inferior con CommonJS tienes que usar require para importar el paquete, por ejemplo:

// import all methods
const EC = require('wdio-wait-for');

browser.waitUntil(EC.alertIsPresent(), { timeout: 5000, timeoutMsg: 'Failed, after waiting for the alert to be present' })
// import specific method
const { alertIsPresent } = require('wdio-wait-for');

browser.waitUntil(alertIsPresent(), { timeout: 5000, timeoutMsg: 'Failed, after waiting for the alert to be present' })

ESM​

Con TypeScript o WebdriverIO v8 y versiones superiores puedes usar la declaración import para importar todos los métodos auxiliares, por ejemplo:

// import all methods
import * as EC from 'wdio-wait-for';

browser.waitUntil(EC.elementToBeEnabled('input'), { timeout: 5000, timeoutMsg: 'Failed, after waiting for the element to be enabled' })

o solo específicos, por ejemplo:

// import specific method
import { elementToBeEnabled } from 'wdio-wait-for';

browser.waitUntil(elementToBeEnabled('input'), { timeout: 5000, timeoutMsg: 'Failed, after waiting for the element to be enabled' })

Esperar una alerta​

Este fragmento de código muestra cómo usar condiciones

browser.waitUntil(alertIsPresent(), { timeout: 5000, timeoutMsg: 'Failed, after waiting for the alert to be present' })

Esperar Elementos​

Este fragmento de código muestra cómo usar condiciones para esperar, por ejemplo, un cierto número de elementos que existan:

browser.waitUntil(numberOfElementsToBe('.links', 2), { timeout: 5000, timeoutMsg: 'Failed, after waiting for the 2 elements' })

Licencia​

Licencia MIT.

Autor​

Yevhen Laichenkov - elaichenkov@gmail.com
Christian Bromann - mail@bromann.dev

Welcome! How can I help?

WebdriverIO AI Copilot