メインコンテンツにスキップ

便利な期待される条件のライブラリService

wdio-wait-for はサードパーティ製のパッケージです。詳細については、GitHub | npm を参照してください。

wdio-wait-for は、WebdriverIO 用の Node.js ライブラリで、定義されたタスクが完了するまで特定の条件を待機する機能を提供する一般的な条件のセットを提供します。

インストール

プロジェクトで wdio-wait-for を使用するには、以下を実行します。

npm i -D wdio-wait-for

Yarn を使用する場合は、以下を実行します。

yarn add --dev wdio-wait-for

API

インポート

CommonJS

CommonJS で WebdriverIO v7 以前を使用している場合は、パッケージをインポートするために require を使用する必要があります。例:

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

TypeScript または WebdriverIO v8 以降では、import ステートメントを使用して、すべてのヘルパーメソッドをインポートできます。例:

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

または特定のメソッドだけをインポートできます。例:

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

アラートを待つ

このコードスニペットは、条件を使用する方法を示しています

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

要素を待つ

このコードスニペットは、特定の数の要素が存在するのを待つなどの条件を使用する方法を示しています

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

ライセンス

MITライセンス.

作成者

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

ようこそ!何かお手伝いできることはありますか?

WebdriverIO AI Copilot