@japa/browser-client
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

@japa/browser-client

Browser client to write end to end browser tests. Uses playwright under the hood

gh-actions-image npm-image license-image typescript-image

The browser client of Japa is built on top of Playwright library and integrates seamlessly with the Japa test runner. Following are some reasons to use this plugin over manually interacting with the Playwright API.

  • Automatic management of browsers and browser contexts.
  • Built-in assertions.
  • Ability to extend the browser, context, and page objects using decorators.
  • Class-based pages and interactions to de-compose the page under test into smaller and reusable components.
  • Toggle headless mode, tracing, and browsers using CLI flags.

Installation

Install the package from the npm registry as follows:

npm i -D playwright @japa/browser-client

yarn add -D playwright @japa/browser-client

Usage

You can use the browser client package with the @japa/runner as follows.

import { assert } from '@japa/assert'
import { browserClient } from '@japa/browser-client'
import { configure, processCliArgs } from '@japa/runner'

configure({
  ...processCliArgs(process.argv.slice(2)),
  ...{
    plugins: [
      assert(),
      browserClient({
        runInSuites: ['browser'],
      }),
    ],
  },
})

Once done, you will be able to access the visit, browser and browserContext property from the test context.

test('test title', ({ browser, browserContext, visit }) => {
  // Create new page
  const page = await browserContext.newPage()
  await page.goto(url)

  // Or use visit helper
  const page = await visit(url)

  // Create multiple contexts
  const context1 = await browser.newContext()
  const context2 = await browser.newContext()
})

Readme

Keywords

none

Package Sidebar

Install

npm i @japa/browser-client

Weekly Downloads

318

Version

2.0.3

License

MIT

Unpacked Size

95.2 kB

Total Files

28

Last publish

Collaborators

  • virk
  • romainlanz
  • julien-r44