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

playwright-record-and-mock

v0.2.1

Published

## a playwright tool for record api and replay

Downloads

42

Readme

Api recorder and mock tool for playwright

a playwright tool for record api and replay

Why this tool born?

Why not use playwright native recordHar option?

The recordHar function of playwright use exact match of url,body,headers content for mock data.

This tool will record api data by request order, and replay them with the same order.

Precondition

⚠️ Must install @playwright/test.

Install

yarn add -D @playwright/test playwright-record-and-mock

Usage steps

After install it, the pram cli is avalable, it is the shortcase of playwright-record-and-mock.

  1. Create playwright ts format config, content like below.

    import type { PlaywrightTestConfig } from '@playwright/test'
    
    const config: PlaywrightTestConfig = {
      projects: [
        {
          name: 'Chrome Stable',
          testDir: 'e2e',
          use: {
            headless: false,
            browserName: 'chromium',
            channel: 'chrome',
            viewport: { width: 1920, height: 1080 },
          },
        },
      ],
    }
    export default config
  2. run pram command for configure.

    pram init

    The command will change playwright.config.ts content.

    Then the playwright.config.ts should like below.

    import type { PlaywrightTestConfig } from '@playwright/test'
    import type { PramConfig } from 'playwright-record-and-mock'
    
    const config: PlaywrightTestConfig & PramConfig = {
      projects: [
        {
          name: 'Chrome Stable',
          testDir: 'e2e',
          use: {
            headless: false,
            browserName: 'chromium',
            channel: 'chrome',
            viewport: { width: 1920, height: 1080 },
          },
        },
      ],
      pram: {
        outDir: 'e2e',
        site: 'https://your.host/',
        urlFilter: /\/api\//,
      },
    }
    export default config

    Or else you can copy the pram part into playwright.config.ts by yourself.

  3. run record by pram command.

    Record your test case in the browser by your own.

    yarn pram mytest1

    After record some browser acitons, close the browser and it will create dir e2e/mytest1, which contains the test case files.

    The test case file will looks like below.

    import { test, expect } from '@playwright/test'
    import { mock } from "playwright-record-and-mock"
    
    test('test', async ({ page }) => {
      mock(page, __dirname)
      ...
    })
    

    For now, pram finishes its work, the next is all the work of playwright.

  4. run playwright test.

yarn playwright test

Api support.

  • json

  • text

TODO

  • custom plugable rule for record and mock.