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

pomify

v0.8.6

Published

Playwright js framework for page objects and explicit locators

Downloads

20

Readme

pomify

Introduction

pomify is a TypeScript library that simplifies creating and maintaining tests using the Playwright testing framework and the Page Object Pattern. It provides a clean structure for organizing UI element locators and interactions, enhancing test readability and maintainability.

Installation

npm install pomify

Usage

pomify utilizes a base class (BasePage) to define core functionalities for page objects. You extend this class to create specific page objects for different pages in your application.

Defining Page Objects

  1. Create a class extending BasePage.
  2. Implement the abstract $ property by assigning specific locators for your page elements. Utilize methods from is (e.g., this.is.Button('#login')) to create element locators.

Example:

// login.page.ts

import { BasePage } from 'pomify';

export class LoginPage extends BasePage {

  $ = {
    usernameInput: this.is.Input('#username'),
    passwordInput: this.is.Input('#password'),
    loginBtn: this.is.Button('#login'),
    errorMsgDiv: this.is.Typography('#alert')
  }

  async goto(){
    //...
  }

  async login(username: string, password: string) {
    await this.$.usernameInput.fill(username);
    await this.$.passwordInput.fill(password);
    await this.$.loginBtn.click();
  }
}

Using Page Objects

  • Create an instance of your page object class with a Playwright Page object.
  • Access element locators and interact with them using methods provided by the page object or the underlying locators (e.g., await loginPage.$.username.fill('test')).

Example:

// login.spec.ts

import { expect, test } from '@playwright/test'
import LoginPage from '../pages/login/login.page';

test.describe('LOGIN TESTS', () => {

    test('login and go to the home page', async ({ page }) => {
        const login = new LoginPage(page);
        
        await login.goto()
        await login.login()
        await page.waitForURL('home')

        expect(page.url()).toContain('home')
    })

    test('error message please insert password', async ({ page }) => {
        const login = new LoginPage(page)

        await login.goto()
        await login.$.usernameInput.fill('Moshe');
        await login.$.loginBtn.click()

        expect(await login.$.errorMsgDiv.innerText()).toContain('Please insert password')
    })

})

API Reference

BaseLocator

  • Properties:
    • page (protected, Playwright Page object)
    • $ (public, Playwright Locator object)
  • Constructor:
    • BaseLocator(page: Page, locator: Locator | string, options?: LocatorOptions)
      • page: The Playwright Page object
      • locator: A string selector or a Playwright Locator object
      • options (optional): Options for refining the locator
        • parent: A string selector or a Playwright Locator object representing the parent element
        • position: String ('first', 'last') or number (nth) to filter by position

ButtonLocator (Extends BaseLocator)

  • click: Clicks the button (bound to the underlying locator's click method)

LinkLocator (Extends ButtonLocator)

  • Properties:
    • nextPage: Optional class for creating the next page object when the link is clicked.
    • toUrl: Optional URL to wait for after clicking the link (as string or RegExp).
  • Methods:
    • navigate: Clicks the link, waits for the target URL (if provided) and creates a new page object (if nextPageClass is provided).

InputLocator (Extends BaseLocator)

  • Methods:
    • click: Clicks the input element (bound to the underlying locator's click method)
    • clear: Clears the input element (bound to the underlying locator's clear method)
    • fill: Fills the input element with a value (bound to the underlying locator's fill method)
    • getInputValue: Retrieves the current value of the input element (bound to the underlying locator's inputValue method)
    • specialFill: Fills the input element with additional options (clear, click, multipleValueBy, force, timeout, noWaitAfter)

CheckboxLocator (Extends BaseLocator)

  • Methods:
    • check: Checks the checkbox (bound to the underlying locator's check method)
    • uncheck: Unchecks the checkbox (bound to the underlying locator's uncheck method)
    • isChecked: Checks if the checkbox is currently checked (bound to the underlying locator's isChecked method)
    • setChecked: Sets the checkbox to a specific checked state (bound to the underlying locator's setChecked method)
    • getInputValue: Retrieves the current value of the checkbox (bound to the underlying locator's inputValue method)

RadioLocator (Extends BaseLocator)

  • Properties:
    • values: Array containing possible radio button values (defined in the constructor).
  • Methods:
    • getInputValue: Retrieves the current value of the radio button (bound to the underlying locator's inputValue method) (under development)
    • getRadioByValue: Finds a radio button locator based on its value.
    • whichIsChecked: Returns the checked radio button locator (if any).
    • check: Checks a radio button by its value.

TypographyLocator

  • Methods:
    • innerText: Retrieves the inner text of the element (bound to the underlying locator's innerText method)