npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@quickpickle/playwright

v0.10.0

Published

Support files for running tests with Playwright using QuickPickle (Gherkin in Vitest).

Downloads

784

Readme

@quickpickle/playwright

@quickpickle/playwright is an extension for QuickPickle that integrates Playwright for end-to-end testing of web applications in a full browser context.

Features

  • A custom world constructor with a configurable browser
  • Pre-defined step definitions for common browser actions and assertions
  • Support for easy visual regression testing
  • Support for multiple browsers (Chromium, Firefox, WebKit)
  • Configuration options for the browser and the test runner

Installation

npm install --save-dev quickpickle @quickpickle/playwright

Usage

Setup quickpickle with Vitest

First set up vitest to recognize your features and setup files. This is the example from the quickpickle documentation:

// vite.config.ts
import { quickpickle } from 'quickpickle';

export default {
  plugins: [
    quickpickle() // <-- Add the quickpickle plugin
  ],
  test: {
    include : [
      'features/*.feature', // <-- Add Gherkin feature files into "test" configuration
      // (you'll probably want other test files too, for unit tests etc.)
    ],
    setupFiles: ['./tests/tests.steps.ts'] // <-- specify each setupfile here
  },
};

Using the default PlaywrightWorld constructor

To use the default PlaywrightWorld constructor, import @quickpickle/playwright/world in one of your setup files:

// tests/tests.steps.ts
import '@quickpickle/playwright/world'

Using the provided step definitions

@quickpickle/playwright provides a wide range of step definitions for common actions and assertions related to UI testing in a browser context. These step definitions are available in the following files, which can also be imported in your setup files:

// tests/tests.steps.ts
import '@quickpickle/playwright/actions'
import '@quickpickle/playwright/outcomes'

Note that these step definitions are NOT STABLE, and this is the primary reason this package has not achieved a full release. What we want is to define a set of step definitions that can be used across all projects for UI testing, and we're probably not really close.

Extending the PlaywrightWorld constructor

You can extend the PlaywrightWorld constructor to meet your own environmental requirements:

import { PlaywrightWorld, PlaywrightWorldConfig } from '@quickpickle/playwright';
import type { TestContext } from 'vitest';
import type { QuickPickleWorldInterface } from 'quickpickle';

export class CustomPlaywrightWorld extends PlaywrightWorld {
  customProperty: string;

  constructor(context: TestContext, info: QuickPickleWorldInterface['info'], worldConfig: Partial<PlaywrightWorldConfig> = {}) {
    super(context, info, worldConfig);
    this.customProperty = 'Custom value';
  }

  async init() {
    await super.init();
    // Add custom initialization logic here
    console.log('Custom world initialized');
  }

  customMethod() {
    console.log(`Custom method called with ${this.customProperty}`);
  }
}

// Don't forget to set the world constructor
import { setWorldConstructor } from 'quickpickle';
setWorldConstructor(CustomPlaywrightWorld);

Configuring the PlaywrightWorld constructor

The PlaywrightWorld constructor can be configured by passing an object to the quickpickle Vite plugin builder, or by passing a quickpickle configuration object to the "test" object. Both of these are demonstrated in the file below, but only one is needed:

// vite.config.ts
import { quickpickle } from 'quickpickle';

export default {
  plugins: [
    quickpickle({ // <-- add the quickpickle plugin

      // General quickpickle configuration
      explodeTags: [
        ['nojs','js'],
        ['chromium','firefox','webkit'],
        ['mobile','tablet','desktop','widescreen'],
      ],

      // PlaywrightWorld configuration
      worldConfig: {
        port: 5173, // sets the port
        slowMo: 50, // turns on "slowMo" for 50ms
      }

    })
  ],
  test: {
    include : [
      'features/*.feature',
    ],
    setupFiles: ['./tests/tests.steps.ts'],
    quickpickle: {

      // General quickpickle configuration
      explodeTags: [
        ['nojs','js'],
        ['chromium','firefox','webkit'],
        ['mobile','tablet','desktop','widescreen'],
      ],

      // PlaywrightWorld configuration
      worldConfig: {
        port: 5173, // sets the port
        slowMo: 50, // turns on "slowMo" for 50ms
      }

    }
  },

The full list of options, with defaults, is here:

export type PlaywrightWorldConfigSetting = Partial<{
  host: string, // default host, including protocol (default: http://localhost)
  port: number, // port to which the browser should connect (default: undefined)
  screenshotDir: string, // directory in which to save screenshots (default: "screenshots")
  nojsTags: string|string[] // tags for scenarios to run without javascript (default: @nojs, @noscript)
  showBrowserTags: string|string[] // tags for scenarios to run with browser visible (default: @browser, @show-browser, @showbrowser)
  slowMoTags: string|string[] // tags for scenarios to be run with slow motion enabled (default: @slowmo)
  headless: boolean // whether to run the browser in headless mode (default true)
  slowMo: boolean|number // whether to run the browser with slow motion enabled (default false)
  slowMoMs: number // the number of milliseconds to slow down the browser by (default 500)
  keyboardDelay: number // the number of milliseconds between key presses (default:20)
  defaultBrowser: 'chromium'|'firefox'|'webkit' // the default browser to use (default: chromium)
  browserSizes: Record<string,string> // the default browser sizes to use, in the form "widthxheight"
  // (default: { mobile: "480x640", tablet: "1024x768", desktop: "1920x1080", widescreen: "3440x1440" })
  defaultBrowserSize: string // the default browser size to use (default: desktop)
}>

Use @quickpickle/playwright in CI

In order to run playwright tests in CI, you'll need to set up the playwright browsers. See quickpickle's release.yml Github action for example.