npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expected-condition-playwright

v1.0.1

Published

expected-condition-playwright is a Node.js library with useful expected condition class

Downloads

1,776

Readme

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
import { ExpectedCondition as EC } from 'expected-condition-playwright';

// Simple selector
const submitButton = 'button';

// Use page's waitForFunction method to provide the elementToBeClickable method to instruct a command to wait until the element is clickable by the selector
await page.waitForFunction(EC.elementToBeClickable(submitButton), submitButton, { timeout: 5000 });

JavaScript

// Require ExpectedCondition class as EC shortcut
const { ExpectedCondition: EC } = require('expected-condition-playwright');

// Simple selector
const submitButton = 'button';

// Use page's waitForFunction method to provide the elementToBeClickable method to instruct a command to wait until the element is clickable by the selector
await page.waitForFunction(EC.elementToBeClickable(submitButton), submitButton, { timeout: 5000 });

Types of Expected Conditions

attributeValueToBe

An expectation for checking element with given selector has attribute with a specific value

Usage

const inputSelector = 'input[type=q]';
const expectedAttribute = 'type';
const expectedValue = 'q';

await page.waitForFunction(
  EC.attributeValueToBe([inputSelector, expectedAttribute, expectedValue]),
  [inputSelector, expectedAttribute, expectedValue],
  { timeout: 5000 },
);

attributeValueContains

An expectation for checking element with given selector has attribute which contains a specific value

Usage

const inputSelector = 'input[type=que]';
const expectedAttribute = 'type';
const expectedValue = 'q';

await page.waitForFunction(
  EC.attributeValueContains([inputSelector, expectedAttribute, expectedValue]),
  [inputSelector, expectedAttribute, expectedValue],
  { timeout: 5000 },
);

attributeToBeNotEmpty

An expectation for checking element with given selector any non empty value for given attribute

Usage

const inputSelector = 'input[type=que]';
const expectedAttribute = 'type';

await page.waitForFunction(
  EC.attributeValueContains([inputSelector, expectedAttribute]),
  [inputSelector, expectedAttribute],
  { timeout: 5000 },
);

numberOfElementsToBe

An expectation for checking number of elements with given selector

Usage

const links = 'a';
const expectedNumber = '12';

await page.waitForFunction(EC.numberOfElementsToBe([links, expectedNumber]), [links, expectedNumber], {
  timeout: 5000,
});

invisibilityOf

An expectation for checking the element to be invisible

Usage

const link = 'a';

await page.waitForFunction(EC.invisibilityOf(link), links, { timeout: 5000 });

textToBePresentInElement

An expectation for checking if the given text is present in the specified element.

Usage

const logInButton = 'button';
const expectedText = 'Log in';

await page.waitForFunction(EC.textToBePresentInElement([logInButton, expectedText]), [logInButton, expectedText], {
  timeout: 5000,
});

textToBePresentInElementValue

An expectation for checking if the given text is present in the specified elements value attribute.

Usage

const userField = 'input';
const expectedValue = 'John';

await page.waitForFunction(EC.textToBePresentInElementValue([userField, expectedValue]), [userField, expectedValue], {
  timeout: 5000,
});

elementToBeClickable

An expectation for checking the element is visible and enabled such that you can click it.

Usage

const nextButton = 'button';

await page.waitForFunction(EC.elementToBeClickable(nextButton), nextButton, { timeout: 5000 });

elementToBeSelected

An expectation for checking the element is visible and enabled such that you can click it.

Usage

const checkbox = 'input';

await page.waitForFunction(EC.elementToBeSelected(checkbox), checkbox, { timeout: 5000 });

titleEquals

An expectation for checking the title of a page.

Usage

const expectedTitle = 'Playwright';

await page.waitForFunction(EC.titleEquals(expectedTitle), expectedTitle, { timeout: 5000 });

titleContains

An expectation for checking that the title contains a case-sensitive substring

Usage

const expectedTitle = 'Play';

await page.waitForFunction(EC.titleContains(expectedTitle), expectedTitle, { timeout: 5000 });

urlEquals

An expectation for the URL of the current page to be a specific url.

Usage

const expectedUrl = 'http://github.com/';

await page.waitForFunction(EC.urlEquals(expectedUrl), expectedUrl, { timeout: 5000 });

urlContains

An expectation for the URL of the current page to contain specific text.

Usage

const expectedUrl = '.com';

await page.waitForFunction(EC.urlContains(expectedUrl), expectedUrl, { timeout: 5000 });

License

expected-condition-playwright is MIT licensed.