You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

playwright-like-cypress

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

playwright-like-cypress

Simplified Playwright API similar to Cypress

latest
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

Playwright Like Cypress

A simplified wrapper around Playwright that provides a Cypress-like API for easier test automation.

Installation

npm install playwright-like-cypress

Setup

To use this library, ensure your Playwright environment is set up. Add this library to your Playwright tests for a more streamlined experience.

Usage

import { SimplePage, SimpleElement } from 'playwright-like-cypress';

// Example usage in a test
const sp = new SimplePage(page);

// Navigate to a URL
await sp.visit('https://example.com');

// Interact with an element
const button = await sp.get('#submit-button');
await button.click();

// Perform assertions
const message = await sp.get('.success-message');
await message.toBeVisible();

// Chainable actions
await (await sp.get('#input-field')).type('Test Input').and();

API Reference

SimplePage

SimplePage serves as the starting point for interacting with your test page.

  • visit(url: string): Promise<void>
    Navigate to the specified URL.

  • get(selector: string): Promise<SimpleElement>
    Find and return a SimpleElement by its selector.

  • contains(text: string, selector?: string): Promise<SimpleElement>
    Find an element containing the specified text, optionally within a specific selector.

  • scrollTo(target: string | { x: number; y: number }): Promise<void>
    Scroll to a position or an element.

  • wait(msOrSelector: number | string): Promise<void>
    Wait for a specific time or element.

  • url(): Promise<string>
    Get the current URL.

SimpleElement

SimpleElement provides easy methods to interact with and test elements.

Interaction Methods

  • click(options?: { force?: boolean }): Promise<void>
    Click the element.

  • type(text: string, options?: { delay?: number }): Promise<void>
    Type text into the element.

  • clear(): Promise<void>
    Clear the input field.

  • check(): Promise<void>
    Check a checkbox or radio button.

  • uncheck(): Promise<void>
    Uncheck a checkbox.

  • select(values: string | string[]): Promise<void>
    Select options in a dropdown.

  • scrollIntoView(): Promise<void>
    Scroll the element into view.

Assertion Methods

  • toBeVisible(): Promise<void>
    Assert that the element is visible.

  • toBeEnabled(): Promise<void>
    Assert that the element is enabled.

  • toBeDisabled(): Promise<void>
    Assert that the element is disabled.

  • toBeChecked(): Promise<void>
    Assert that a checkbox or radio is checked.

  • toHaveText(text: string): Promise<void>
    Assert that the element contains the specified exact text.

  • toContainText(text: string): Promise<void>
    Assert that the element contains the specified text.

  • toHaveValue(value: string): Promise<void>
    Assert that an input field has the specified value.

  • toHaveCount(count: number): Promise<void>
    Assert the number of matching elements.

Navigation and Query Methods

  • eq(index: number): Promise<SimpleElement>
    Find an element at a specific index.

  • find(selector: string): Promise<SimpleElement[]>
    Find child elements matching the selector.

  • parent(): Promise<SimpleElement | null>
    Get the parent element.

  • parents(selector?: string): Promise<SimpleElement[]>
    Get all parent elements, optionally filtered by selector.

  • next(): Promise<SimpleElement>
    Get the next sibling element.

  • prev(): Promise<SimpleElement>
    Get the previous sibling element.

  • not(selector: string): Promise<SimpleElement[]>
    Get elements that do not match the selector.

Example Test Workflow

import { test } from '@playwright/test';
import { SimplePage } from 'playwright-like-cypress';

test('example test', async ({ page }) => {
  const sp = new SimplePage(page);

  // Navigate to the homepage
  await sp.visit('https://example.com');

  // Perform some actions
  const input = await sp.get('#username');
  await input.type('myusername');

  const submit = await sp.get('#submit');
  await submit.click();

  // Validate the results
  const successMessage = await sp.get('.success');
  await successMessage.toBeVisible();
});

License

MIT

FAQs

Package last updated on 29 Dec 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