
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
expect-puppeteer
Advanced tools
The expect-puppeteer package is a set of utility functions that integrate Jest's expect assertions with Puppeteer's browser automation capabilities. It allows for more readable and expressive tests when working with Puppeteer.
toMatch
This feature allows you to assert that a specific text appears on the page. It simplifies the process of checking for text content within the page.
await expect(page).toMatch('text to match');
toClick
This feature allows you to simulate a click event on a specified element. It is useful for testing interactions with buttons, links, and other clickable elements.
await expect(page).toClick('button#submit');
toFill
This feature allows you to fill out form fields with specified values. It is useful for testing form submissions and input handling.
await expect(page).toFill('input[name="username"]', 'myUsername');
toSelect
This feature allows you to select an option from a dropdown menu. It is useful for testing interactions with select elements.
await expect(page).toSelect('select#dropdown', 'optionValue');
toUploadFile
This feature allows you to simulate file uploads by specifying the file path. It is useful for testing file input elements.
await expect(page).toUploadFile('input[type="file"]', 'path/to/file.txt');
jest-puppeteer provides a set of utilities to run Puppeteer with Jest. It offers a more comprehensive setup for integrating Puppeteer with Jest, including custom environment setup and teardown, but it does not include the same level of syntactic sugar for assertions as expect-puppeteer.
puppeteer-testing-library is a set of utilities for using the Testing Library queries with Puppeteer. It focuses on providing a more user-centric approach to querying and interacting with elements, similar to the philosophy of the Testing Library family of packages.
puppeteer-extra is a modular plugin framework for Puppeteer. It allows you to extend Puppeteer's functionality with plugins, such as stealth mode and adblocker. While it does not provide assertion utilities, it enhances Puppeteer's capabilities in other ways.
Assertion library for Puppeteer.
npm install expect-puppeteer
Without Jest:
import expect from 'expect-puppeteer'
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://google.com')
await expect(page).toMatch('google')
await browser.close()
})()
To use with Jest, just modify your configuration:
{
"setupTestFrameworkScriptFile": "expect-puppeteer"
}
Writing integration test is very hard especially in Single Page Application. Data are loaded asynchronously and it is difficult to know exactly when it will be displayed in the page.
Puppeteer API is great, all this methods are built with it but it is low level and not designed to test an application. This API is designed for integration testing and will wait element before running each action.
instance
<Page|[ElementHandle]> Contextselector
<string> A selector to click onoptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.text
<string> A text or a RegExp to match in element textContent
.await expect(page).toClick('button', { text: 'Home' })
await expect(page).toDisplayDialog(async () => {
await expect(page).toClick('button', { text: 'Show dialog' })
})
instance
<Page|[ElementHandle]> Contextselector
<string> A selector to match fieldvalue
<string> Value to filloptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.await expect(page).toFill('input[name="firstName"]', 'James')
instance
<Page|[ElementHandle]> Contextselector
<string> A selector to match formvalues
<Object> Values to filloptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.await expect(page).toFillForm('form[name="myForm"]', {
firstName: 'James',
lastName: 'Bond',
})
instance
<Page|[ElementHandle]> Contextmatcher
<string> A text or a RegExp to match in pageoptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.// Matching using text
await expect(page).toMatch('Lorem ipsum')
// Matching using RegExp
await expect(page).toMatch('lo.*')
instance
<Page|[ElementHandle]> Contextselector
<string> A selector to match elementoptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.text
<string> A text or a RegExp to match in element textContent
.// Select a row containing a text
const row = await expect(page).toMatchElement('tr', { text: 'My row' })
// Click on the third column link
await expect(row).toClick('td:nth-child(2) a')
instance
<Page|[ElementHandle]> Contextselector
<string> A selector to match select elementvalueOrText
<string> Value or text matching optionoptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.await expect(page).toSelect('select[name="choices"]', 'Choice 1')
instance
<Page|[ElementHandle]> Contextselector
<string> A selector to match input elementfilePath
<string> A file pathoptions
<Object> Optional parameters
polling
<string|number> An interval at which the pageFunction
is executed, defaults to raf
. If polling
is a number, then it is treated as an interval in milliseconds at which the function would be executed. If polling
is a string, then it can be one of the following values:
raf
- to constantly execute pageFunction
in requestAnimationFrame
callback. This is the tightest polling mode which is suitable to observe styling changes.mutation
- to execute pageFunction
on every DOM mutation.timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.import path from 'path'
await expect(page).toUploadFile(
'input[type="file"]',
path.join(__dirname, 'file.txt'),
)
MIT
FAQs
Assertion toolkit for Puppeteer.
The npm package expect-puppeteer receives a total of 223,931 weekly downloads. As such, expect-puppeteer popularity was classified as popular.
We found that expect-puppeteer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.