Aller au contenu principal

Bibliothèque de conditions attendues utiles Service

wdio-wait-for est un package tiers, pour plus d'informations, veuillez consulter GitHub | npm

wdio-wait-for est une bibliothèque Node.js pour WebdriverIO qui fournit un ensemble de conditions communes offrant des fonctionnalités pour attendre certaines conditions jusqu'à ce qu'une tâche définie soit terminée.

Installation

Pour utiliser wdio-wait-for dans votre projet, exécutez :

npm i -D wdio-wait-for

Si vous utilisez Yarn, exécutez :

yarn add --dev wdio-wait-for

API

Exemples

Import

CommonJS

Si vous utilisez WebdriverIO v7 et antérieur avec CommonJS, vous devez utiliser require pour importer le package, par exemple :

// 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

Avec TypeScript ou WebdriverIO v8 et versions ultérieures, vous pouvez utiliser l'instruction import pour importer soit toutes les méthodes d'assistance, par exemple :

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

ou seulement des méthodes spécifiques, par exemple :

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

Attendre une alerte

Cet extrait de code montre comment utiliser les conditions

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

Attendre des éléments

Cet extrait de code montre comment utiliser les conditions pour attendre, par exemple, un certain nombre d'éléments à exister :

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

Licence

Sous licence MIT.

Auteur

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

Welcome! How can I help?

WebdriverIO AI Copilot