Vai al contenuto principale

Libreria di condizioni attese utili - Servizio

wdio-wait-for è un pacchetto di terze parti, per maggiori informazioni si prega di consultare GitHub | npm

wdio-wait-for è una libreria Node.js per WebdriverIO che fornisce un insieme di condizioni comuni che offrono funzionalità per attendere determinate condizioni fino al completamento di un'attività definita.

Installazione

Per utilizzare wdio-wait-for nel tuo progetto, esegui:

npm i -D wdio-wait-for

Se utilizzi Yarn, esegui:

yarn add --dev wdio-wait-for

API

Esempi

Import

CommonJS

Se stai utilizzando WebdriverIO v7 e versioni precedenti con CommonJS devi usare require per importare il pacchetto, ad esempio:

// 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 e versioni successive puoi utilizzare l'istruzione import per importare tutti i metodi helper, ad esempio:

// 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 quelli specifici, ad esempio:

// 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' })

Attesa per un alert

Questo frammento di codice mostra come utilizzare le condizioni

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

Attesa per elementi

Questo frammento di codice mostra come utilizzare le condizioni per attendere, ad esempio, un determinato numero di elementi da esistere:

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

Licenza

MIT licensed.

Autore

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

Welcome! How can I help?

WebdriverIO AI Copilot