Releases: playwright-community/expect-playwright
Version 0.8.0
Add support for Locators! Playwright 1.14 recently released the Locators API which now work when passed to expect-playwright matchers:
await expect(page.locator('button')).toBeEnabled()
Version 0.7.2
Changes:
- fix: toHaveSelector when ElementHandle is passed (#118)
Version 0.7.1
Bug fixes
Fixes an issue in version 0.7.0 where the package output format was unintentionally changed which led to expect-playwright not working.
Version 0.7.0
Version 0.6.0
A lot has changed in expect-playwright
and we are happy to bring you version 0.6.0 with new matchers, automatic promise resolution, improvements to not.toHaveSelector
, and error message diffs!
New matchers!
This release brings 7 new matchers to simplify even more common testing use cases. Below is a quick summary of each new matcher we've added, but checkout the docs for full details showing how to use these new matchers.
toBeChecked
- Checks if a checkbox or radio is checked.toBeDisabled
- Checks if an element is disabled.toBeEnabled
- Checks if an element is enabled.toMatchAttribute
- Checks if an element's attribute matches a given string or regex pattern.toMatchTitle
- Checks if the page or frame title matches a given string or regex pattern.toMatchURL
- Checks if the page or frame URL matches a given string or regex pattern.toMatchValue
- Checks if an element's value matches a given string or regex pattern.
Automatic promise resolution
A recent change allows all expect-playwright matchers to accept a promise which resolves to a page, frame, or element handle so you are not forced to write extra awaits in your tests!
// before
await expect(await page.$('button')).toBeChecked()
// after
await expect(page.$('button')).toBeChecked()
Improved not.toHaveSelector
Previously, using not.toHaveSelector
would wait for 30 second (or the specified timeout) for an element to appear and if it did not appear after that timeout, it would cause the test to pass. While this worked okay, it introduced lots of extra wait time in tests that is often unwanted. The two workarounds were to pass a shorter timeout, or use toHaveSelector(selector, { state: "hidden" })
.
However, neither of these workarounds were ideal so we decided to update the defaults to make not.toHaveSelector
more useful. Now, when calling not.toHaveSelector
, we will wait for the element to be hidden after which your test will continue. This results in more reliable and faster tests!
Error message diffs
Error messages will now display a diff when the expected/received values are similar to help you more easily pinpoint why your tests failed.
Deprecations
Previously, we had several matchers with toEqual
and toHave
variations for exact/substring matching. For example, toEqualText
would check if an elements text matched a given string exactly, while toHaveText
would verify the element's text contained the given string. With our new toMatch
matchers, passing a string will perform an exact match, and passing a regex will perform a regex based match. As such, we are deprecating our toEqual
and toHave
matchers since our new toMatch
matchers cover both use cases.
Below is an example showing the migration path for toEqualText
and toHaveText
.
// before
await expect(element).toEqualText('foo')
await expect(element).toHaveText('bar')
// after
await expect(element).toMatchText('foo')
await expect(element).toMatchText(/bar/)
Acknowledgement
Many thanks to @mskelton for putting so much effort into this package and bringing its feature-set and quality to the next level! ❤️
Version 0.5.1
Fixes:
- fix: add toMatchText to exported matchers (#88)
Version 0.5.0
Version 0.4.1
Version 0.4.0
Changes:
- chore: update dependencies (#70)
- chore: add Prettier (#72)
- feat: improve toEqualText error message and refactor tests (#73)
- chore: improve toEqualUrl and toEqualValue matcher messages (#75)
- chore: Improved matcher message for selector matchers (#76)
- chore: finish matcher updates (#77)
Many thanks to @mskelton for adding the new diff visualization.