Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

playwrigth-ws-inspector

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

playwrigth-ws-inspector

A playwright extension to inspect and validate websocket traffic

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-62.5%
Maintainers
1
Weekly downloads
 
Created
Source

playwright-ws-inspector

Instalation

npm install playwright-ws-inspector --save-dev

Usage

using fixtures
// Fixture file...

import { intercepWsTraffic, PageWithWsInspector } from 'playwrigth-ws-inspector'

const test = baseTest.extend<CustomFixture>({
    createCustomPage: async ({ context }, use) => {
        const maker = async (options: { name: string }): Promise<PageWithWsInspector<CustomPage>> => {
            let page = await context.newPage()
            await intercepWsTraffic(page)
            return page
        }
        await use(maker)
    })

// Test file
test.describe('Test with WS interceptor', () => {
    const page = await createCustomPage({ name: '[page]' })
    await page.goto(SERVER_URL)

    // reset the traffic data (required for ordered tests, but always a good pratice to reduce the test load)
    page.resetWsTraffic()

    //execute any playwright stuff...

    //Test ws traffic on the page
    page.expectWsTraffic({
      assertations: [
        {
          type: "send",
          name: "connect",
          expect: {
            type: "connect",
            "message.version.major": 4,
          },
        }
      ]
    })
})    
no fixtures

import { intercepWsTraffic, PageWithWsInspector } from 'playwrigth-ws-inspector'

const test = baseTest.extend<CustomFixture>({
    createCustomPage: async ({ context }, use) => {
        const maker = async (options: { name: string }): Promise<PageWithWsInspector<CustomPage>> => {
            let page = await context.newPage()
            await intercepWsTraffic(page)
            return page
        }
        await use(maker)
    })

// Test file
test.describe('Test with WS interceptor', async ({ page }) => {
    
    // call `intercepWsTraffic` before calling `page.goto` 
    await intercepWsTraffic(page)

    await page.goto(SERVER_URL)

    // reset the traffic data (required for ordered tests, but always a good pratice to reduce the test load)
    page.resetWsTraffic()

    //execute any playwright stuff...

    //Test ws traffic on the page
    page.expectWsTraffic({
      assertations: [
        {
          type: "send",
          name: "connect",
          expect: {
            type: "connect",
            "message.version.major": 4,
          },
        }
      ]
    })
})
Assertations
PropertyDescripton
type'send' or 'recv'
nameOptional name to help indentify test failures
expectOptional record describing the expected payload
expectNotOptional record describing the not expected payload
Payload description

A payload description is a Record entry with "<json.path>: <number> | <string> | Object(deep equals) | RegEx"

Keywords

FAQs

Package last updated on 29 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc