انتقل إلى المحتوى الرئيسي

مكتبة لشروط مفيدة متوقعة للخدمة

wdio-wait-for هي حزمة طرف ثالث، لمزيد من المعلومات يرجى الاطلاع على GitHub | npm

wdio-wait-for هي مكتبة Node.js لـ WebdriverIO توفر مجموعة من الشروط الشائعة التي توفر وظائف للانتظار حتى تكتمل مهمة محددة.

التثبيت

لاستخدام wdio-wait-for في مشروعك، قم بتشغيل:

npm i -D wdio-wait-for

إذا كنت تستخدم Yarn، قم بتشغيل:

yarn add --dev wdio-wait-for

API

أمثلة

الاستيراد

CommonJS

إذا كنت تستخدم WebdriverIO الإصدار 7 والإصدارات الأقدم مع CommonJS فعليك استخدام 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 الإصدار 8 وما فوق يمكنك استخدام عبارة 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

Welcome! How can I help?

WebdriverIO AI Copilot