Expected Condition
expected-condition-playwright is a Node.js library for Playwright and Puppeteer that supplies a set of common conditions that provides functionalities to wait for certain conditions till a defined task is complete.
Table of Contents
Getting Started
Installation
To use expected-condition-playwright in your project, run:
npm i -D expected-condition-playwright
Import and usage
TypeScript
// Import ExpectedCondition class as EC shortcut; // Simple selector; // Use page's waitForFunction method to provide the elementToBeClickable method to instruct a command to wait until the element is clickable by the selectorawait page.waitForFunctionEC.elementToBeClickablesubmitButton, submitButton, ;
JavaScript
// Require ExpectedCondition class as EC shortcut; // Simple selector; // Use page's waitForFunction method to provide the elementToBeClickable method to instruct a command to wait until the element is clickable by the selectorawait page.waitForFunctionEC.elementToBeClickablesubmitButton, submitButton, ;
Types of Expected Conditions
attributeValueToBe
An expectation for checking element with given selector has attribute with a specific value
Usage
;;; await page.waitForFunction EC.attributeValueToBe, , ,;
attributeValueContains
An expectation for checking element with given selector has attribute which contains a specific value
Usage
;;; await page.waitForFunction EC.attributeValueContains, , ,;
attributeToBeNotEmpty
An expectation for checking element with given selector any non empty value for given attribute
Usage
;; await page.waitForFunction EC.attributeValueContains, , ,;
numberOfElementsToBe
An expectation for checking number of elements with given selector
Usage
;; await page.waitForFunctionEC.numberOfElementsToBe, , ;
invisibilityOf
An expectation for checking the element to be invisible
Usage
; await page.waitForFunctionEC.invisibilityOflink, links, ;
textToBePresentInElement
An expectation for checking if the given text is present in the specified element.
Usage
;; await page.waitForFunctionEC.textToBePresentInElement, , ;
textToBePresentInElementValue
An expectation for checking if the given text is present in the specified elements value attribute.
Usage
;; await page.waitForFunctionEC.textToBePresentInElementValue, , ;
elementToBeClickable
An expectation for checking the element is visible and enabled such that you can click it.
Usage
; await page.waitForFunctionEC.elementToBeClickablenextButton, nextButton, ;
elementToBeSelected
An expectation for checking the element is visible and enabled such that you can click it.
Usage
; await page.waitForFunctionEC.elementToBeSelectedcheckbox, checkbox, ;
titleEquals
An expectation for checking the title of a page.
Usage
; await page.waitForFunctionEC.titleEqualsexpectedTitle, expectedTitle, ;
titleContains
An expectation for checking that the title contains a case-sensitive substring
Usage
; await page.waitForFunctionEC.titleContainsexpectedTitle, expectedTitle, ;
urlEquals
An expectation for the URL of the current page to be a specific url.
Usage
; await page.waitForFunctionEC.urlEqualsexpectedUrl, expectedUrl, ;
urlContains
An expectation for the URL of the current page to contain specific text.
Usage
; await page.waitForFunctionEC.urlContainsexpectedUrl, expectedUrl, ;
License
expected-condition-playwright is MIT licensed.