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

@devoxa/playwright-extra

v2.2.0

Published

Extra utility functions for interacting with Playwright

Downloads

47

Readme

Installation

yarn add @devoxa/playwright-extra

Usage

Assertions

await expectToExist(locator)

Expect the locator to exist exactly once.

await expectNotToExist(locator)

Expect the locator not to exist.

Clipboard

Note: These functions are not thread safe and a potential cause of race conditions.

await getClipboardValue(page)

Get the value of the clipboard.

await setClipboardValue(page, value)

Set the value of the clipboard.

Accessability

await expectZeroAccessibilityViolations(page, config?)

Expect that there are no accessibility violations. This is a wrapper around axe-playwright, and takes the same config as configureAxe. The assertion can be turned off globally by setting process.env.DISABLE_ACCESSIBILITY_TESTS to true.

JSON Lines

Note: You can read more about the JSON Lines format here.

await jsonLinesAppend(filePath, line)

Append a line to a file in JSON Lines format.

await jsonLinesParse(filePath)

Parse a file in JSON Lines format.

Local Storage

await getLocalStorageItem(page, key)

Get the value of a local storage item.

await setLocalStorageItem(page, key, value)

Set the value of a local storage item.

await removeLocalStorageItem(page, key)

Remove a local storage item.

Console Messages

const getConsoleMessages = captureConsoleMessages(page)
// ... do things here ...
expect(getConsoleMessages()).toEqual([])
expect(getConsoleMessages(['warning', 'error'])).toEqual([])

Capture the console messages of the page for later assertions.

Matchers

Note: These functions escape special regular expression characters, so they are safe to use for example for URLs with query strings.

await expect(page).toHaveURL($startsWith(value))

const dynamicSegments = { id: '[0-9]+' }
await expect(page).toHaveURL($startsWith('/:id/edit', dynamicSegments))

Create a RegExp that starts with the value, with optional dynamicSegments replaced with their respective regular expressions.

await expect(page).toHaveURL($contains(value))

const dynamicSegments = { id: '[0-9]+' }
await expect(page).toHaveURL($contains('/:id/edit', dynamicSegments))

Create a RegExp that contains the value, with optional dynamicSegments replaced with their respective regular expressions.

await expect(page).toHaveURL($endsWith(value))

const dynamicSegments = { id: '[0-9]+' }
await expect(page).toHaveURL($endsWith('/:id/edit', dynamicSegments))

Create a RegExp that ends with the value, with optional dynamicSegments replaced with their respective regular expressions.

Performance Metrics

const options = { filePath: 'performance-metrics.jsonl' }

await exportPerformanceMetrics(page, label, options?)

Export the performance metrics of the page to the file path. The output is in JSON Lines format, and includes the label, encodedBodySize, resourceLoadDuration and nextjsHydrationDuration.

  • Make sure to call the function right after loading the page to get correct results.
  • The performance-metrics.jsonl file has to be manually removed, e.g. before running the tests.
  • You can test the resulting export with the yarn test-performance-metrics CLI tool. See --help for the available options.

Retry On Error

const options = { timeout: 5000, waitTime: 100 }

await retryOnError(asyncCallback, options?)

Retry until the callback is successful or the timeout is hit. This is useful for unstable parts of tests, for example when waiting for an email that is sent out by a queue processor.

Wait For Network Idle

const options = { timeout: 10000, minIdleTime: 200, debug: false }

const waitForNetworkIdlePromise = waitForNetworkIdle(page, options?)
// ... do things here ...
await waitForNetworkIdlePromise

Wait for all network requests to be settled before resolving.

await gotoAndWaitForNetworkIdle(page, url, options?)

Go to a page and wait for all network requests to be settled.

await reloadAndWaitForNetworkIdle(page, url, options?)

Reload the page and wait for all network requests to be settled.

WaitForNetworkIdleDefaultOptions.minIdleTime = 500

Set the global default options for all *waitForNetworkIdle functions.

Keep in mind that test files run independently from the setup, so you have to call this in a helper, that is imported into all test files.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT