Hoppa till huvudinnehåll

Bibliotek av användbara förväntade villkor Service

wdio-wait-for är ett tredjepartspaket, för mer information se GitHub | npm

wdio-wait-for är ett Node.js-bibliotek för WebdriverIO som tillhandahåller en uppsättning gemensamma villkor som ger funktioner för att vänta på vissa förhållanden tills en definierad uppgift är klar.

Installation

För att använda wdio-wait-for i ditt projekt, kör:

npm i -D wdio-wait-for

Om du använder Yarn, kör:

yarn add --dev wdio-wait-for

API

Examples

Import

CommonJS

Om du använder WebdriverIO v7 och lägre med CommonJS måste du använda require för att importera paketet, t.ex.:

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

Med TypeScript eller WebdriverIO v8 och uppåt kan du använda import-satsen för att importera antingen alla hjälpmetoder, t.ex.:

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

eller bara specifika, t.ex.:

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

Wait for alert

Detta kodavsnitt visar hur man använder villkor

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

Wait for Elements

Detta kodavsnitt visar hur man använder villkor för att vänta t.ex. på ett visst antal element att existera:

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

License

MIT licensed.

Author

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

Welcome! How can I help?

WebdriverIO AI Copilot