
Security Fundamentals
Obfuscation 101: Unmasking the Tricks Behind Malicious Code
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
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"
}
selector
<string> A selector to click onoptions
<Object> Optional parameters
await expect(page).toClick('button', { text: 'Home' })
await expect(page).toDisplayDialog(async () => {
await expect(page).toClick('button', { text: 'Show dialog' })
})
selector
<string> A selector to match fieldvalue
<string> Value to filloptions
<Object> Optional parameters
timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.await expect(page).toFill('input[name="firstName"]', 'James')
selector
<string> A selector to match formvalues
<Object> Values to filloptions
<Object> Optional parameters
timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.await expect(page).toFillForm('form[name="myForm"]', {
firstName: 'James',
lastName: 'Bond',
})
text
<string> A text to match in pageoptions
<Object> Optional parameters
timeout
<number> maximum time to wait for in milliseconds. Defaults to 500
.await expect(page).toMatch('Lorem ipsum')
selector
<string> A selector to match select elementvalueOrText
<string> Value or text matching optionawait expect(page).toSelect('select[name="choices"]', 'Choice 1')
import path from 'path'
await expect(page).toUploadFile(
'input[type="file"]',
path.join(__dirname, 'file.txt'),
)
MIT
FAQs
Assertion toolkit for Puppeteer.
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 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.
Security News
Biome's v2.0 beta introduces custom plugins, domain-specific linting, and type-aware rules while laying groundwork for HTML support and embedded language features in 2025.