All Projects → playwright-community → Expect Playwright

playwright-community / Expect Playwright

Licence: mit
Jest utility matcher functions to simplify expect statements for the usage with Playwright.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Expect Playwright

Testdeck
Object oriented testing
Stars: ✭ 206 (+212.12%)
Mutual labels:  jest, testing-tools
jest-wrap
Fluent pluggable interface for easily wrapping `describe` and `it` blocks in Jest tests.
Stars: ✭ 35 (-46.97%)
Mutual labels:  jest, testing-tools
saloon
An E2E test seeder for enterprise web applications
Stars: ✭ 30 (-54.55%)
Mutual labels:  e2e-tests, testing-tools
Express Typescript Boilerplate
A delightful way to building a RESTful API with NodeJs & TypeScript by @w3tecch
Stars: ✭ 2,293 (+3374.24%)
Mutual labels:  jest, e2e-tests
React Adventure
⛰ React high-ending architecture & patterns ready for use. Made for big and small projects. PWA Ready.
Stars: ✭ 62 (-6.06%)
Mutual labels:  jest, e2e-tests
Chromogen
UI-driven Jest test-generation package for Recoil selectors
Stars: ✭ 164 (+148.48%)
Mutual labels:  jest, testing-tools
expo-detox-typescript-example
Sample Expo app with e2e tests using detox, jest and typescript
Stars: ✭ 81 (+22.73%)
Mutual labels:  jest, e2e-tests
Npm Registry Browser
Browse the npm registry with an SPA made in React, with full dev workflow.
Stars: ✭ 97 (+46.97%)
Mutual labels:  jest, e2e-tests
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+53150%)
Mutual labels:  testing-tools, e2e-tests
puppeteer-screenshot-tester
Small library that allows us to compare screenshots generated by puppeteer in our tests.
Stars: ✭ 50 (-24.24%)
Mutual labels:  jest, testing-tools
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+21075.76%)
Mutual labels:  jest, e2e-tests
Aws Testing Library
Chai (https://chaijs.com) and Jest (https://jestjs.io/) assertions for testing services built with aws
Stars: ✭ 52 (-21.21%)
Mutual labels:  jest, e2e-tests
Gest
👨‍💻 A sensible GraphQL testing tool - test your GraphQL schema locally and in the cloud
Stars: ✭ 109 (+65.15%)
Mutual labels:  jest, testing-tools
Root Cause
🔍 Root Cause is a tool for troubleshooting Puppeteer and Playwright tests. 🔎
Stars: ✭ 205 (+210.61%)
Mutual labels:  jest, e2e-tests
Consolemock
A tool for testing console logs
Stars: ✭ 103 (+56.06%)
Mutual labels:  jest, testing-tools
software-testing-resource-pack
Various files useful for manual testing and test automation etc.
Stars: ✭ 38 (-42.42%)
Mutual labels:  e2e-tests, testing-tools
jest-dashboard
Command Line Dashboard for Jest
Stars: ✭ 61 (-7.58%)
Mutual labels:  jest, testing-tools
Detox
High velocity native mobile development requires us to adopt continuous integration workflows, which means our reliance on manual QA has to drop significantly. Detox tests your mobile app while it’s running in a real device/simulator, interacting with it just like a real user.
Stars: ✭ 8,988 (+13518.18%)
Mutual labels:  e2e-tests, testing-tools
React Native Learning Resources
Collection of some good resources for react-native ✨ 🔥 💥
Stars: ✭ 61 (-7.58%)
Mutual labels:  jest, e2e-tests
Internet.nl
Internet standards compliance test suite
Stars: ✭ 56 (-15.15%)
Mutual labels:  testing-tools

expect-playwright

Node.js CI codecov NPM

This library provides utility matchers for Jest in combination with Playwright. All of them are exposed on the expect object. You can use them either directly or invert them via the .not property like shown in a example below.

npm install -D expect-playwright playwright-core

Usage

With Jest

To activate it in your Jest environment you have to include it in your configuration.

{
    "setupFilesAfterEnv": ["expect-playwright"]
}

Without Jest

import expect from "expect-playwright"

await expect(page).toHaveText("#foo", "my text")

Why do I need it

The Playwright API is great, but it is low level and not designed for integration testing. So this package tries to provide a bunch of utility functions to perform the common checks easier.

Example which should wait and compare the text content of a paragraph on the page.

// before
await page.waitForSelector("#foo")
const textContent = await page.$eval("#foo", el => el.textContent)
expect(textContent).stringContaining("my text")

// after by using expect-playwright
await expect(page).toHaveText("#foo", "my text")

API documentation

Table of Contents

toHaveSelector

expect(page: Page).toHaveSelector(selector: string, options?: PageWaitForSelectorOptions)

This function waits as a maximum as the timeout exceeds for a given selector once it appears on the page.

await expect(page).toHaveSelector("#foobar")
// or via not, useful to only wait 1 second instead of for the default timeout by Playwright which is 30 seconds.
await expect(page).not.toHaveSelector("#foobar", {
  timeout: 1 * 1000
})

toHaveFocus

expect(page: Page).toHaveFocus(selector: string, options?: PageWaitForSelectorOptions)

This function checks if the given selector has focus.

await expect(page).toHaveFocus("#foobar")
// or via not, useful to only wait 1 second instead of for the default timeout by Playwright which is 30 seconds.
await expect(page).not.toHaveFocus("#foobar", {
  timeout: 1 * 1000
})

toEqualUrl

expect(page: Page).toHaveSelector(value: string)

This function checks if the given URL matches the current page's URL

await expect(page).toEqualUrl("https://github.com")

toHaveSelectorCount

expect(page: Page).toHaveSelector(selector: string, value: number, options?: PageWaitForSelectorOptions)

This function checks if the count of a given selector is the same as the provided value.

await expect(page).toHaveSelectorCount(".my-element", 3)

toHaveText

This function checks if the textContent of a given element contains the provided value.

You can do this via a selector on the whole page:

expect(page: Page).toHaveText(selector: string, value: string, options?: PageWaitForSelectorOptions)

await expect(page).toHaveText("#my-element", "MyValue")

Or without a selector which will use the body element:

expect(page: Page).toHaveText(value: string)

await expect(page).toHaveText("Playwright")

Or by passing a Playwright ElementHandle:

expect(page: ElementHandle).toHaveText(value: string)

const element = await page.$('#my-element');
await expect(element).toHaveText("Playwright")

toEqualText

This function checks if the textContent of a given element is the same as the provided value.

You can do this via a selector on the whole page:

expect(page: Page).toEqualText(selector: string, value: string, options?: PageWaitForSelectorOptions)

await expect(page).toEqualText("#my-element", "Playwright")

Or without a selector which will use the body element:

expect(page: Page).toEqualText(value: string, options?: PageWaitForSelectorOptions)

await expect(page).toEqualText("Playwright")

Or by passing a Playwright ElementHandle:

expect(page: ElementHandle).toEqualText(value: string, options?: PageWaitForSelectorOptions)

const element = await page.$('#my-element');
await expect(element).toEqualText("Playwright")

toEqualValue

This function checks if the value of a given element is the same as the provided value.

You can do this via a selector or the element directly:

expect(page: Page).toEqualValue(selector: string, value: string, options?: PageWaitForSelectorOptions)

await expect(page).toEqualValue("#my-element", "Playwright")

Or by passing a Playwright ElementHandle:

expect(page: ElementHandle).toEqualValue(value: string, options?: PageWaitForSelectorOptions)

const element = await page.$('#my-element');
await expect(element).toEqualValue("Playwright")

Examples

import playwright from 'playwright-chromium'

describe("GitHub Playwright project", () => {
  it("should should have Playwright in the README heading", async () => {
    const browser = await playwright.chromium.launch()
    const page = await browser.newPage()
    await page.goto("https://github.com/microsoft/playwright")
    await expect(page).toHaveText("#readme h1", "Playwright")
    // or also all of them via the not property
    await expect(page).not.toHaveText("this-is-no-anywhere", { timeout: 1 * 1000 })
    await browser.close()
  })
})

TypeScript

There are typings available. For that just import

import "expect-playwright"

at the top of your test file or include it globally in your tsconfig.json.

Inspired by

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].