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

puppeteer-toolkit

v0.4.5-alpha.20

Published

A toolkit for puppeteer to greatly improves test case development efficiency.

Downloads

6

Readme

puppeteer-toolkit

A toolkit for DOM operation with puppeteer in nodejs environment, which greatly improves test case development efficiency

Why

I got tired of writing so many callbacks for DOM operations with puppeteer api.

Installation

npm install puppeteer-toolkit --save-dev

This project already contains typings files, just enjoy programing with TypeScript

Usage

import puppeteer from 'puppeteer'
import $ from 'puppeteer-toolkit'

(async ()=>{
    let browser = await puppeteer.launch()

    // puppeteer-toolkit would init with browser and set the default page to be the current page.
    await $.setBrowser(await browser.pages())

    const $body = $('body')

    if(await $body.hasClass('some-class')){
        const id = await $body.find('.item:eq(0)').attr('id')
    }

    ...
})();

Except some event trigger and some methods, most of DOM api are based on zeptojs, which would be injected when page on load.

zepto.js Doc

What's different from zepto.js is that, puppeteer-toolkit only supports getting data from dom but not setting data to dom or changing dom.

In chromium page, it was modified for puppeteer-toolkit and exposes $Z namespace.

Methods return instance of VSelector

has, not, parents, parent, children, siblings, prev, next, find, eq, first, last

jQuery CSS extensions is supported, such as $('div:first') and el.is(':visible').

const body: VSelector = $('body')
const header: VSelector = body.find('header')
const li1: VSelector = header.find('li').eq(1)
const ul: VSelector = li1.parents('ul:visible')

The instance of VSelector do nothing with document

Methods return Promise<string | number | boolean | any>

text, html, height, width, offset, offsetParent, position, val, index, scrollTop, css, attr, prop, data, is, hasClass

All above methods can be used for test cases under waitFor and expect

VSelector.waitFor.X(name?, expectedValue?, options?:{timeout: 1000, delay: 100}):Promise<void>

By default, it checks to be the expected value every 100ms and it would throw TimeoutError if failed to get the expected value after 1000ms

await $('div.loading').waitFor.hasClass('hidden')
await $('div.dialog').waitFor.css('display', 'block', {
    timeout: 3000,
    delay: 1000
})

VSelector.expect.X(name?, expectValue?):Promise<void>

It checks the value immediately, and throw ExpectError if failed to get the expected value

await $('div.loading').expect.hasClass('hidden')
await $('div.dialog').expect.css('display', 'block')

Event Triggers

All event triggers are based on api of puppeteer and do some functional packaging

VSelector.click(options?): Promise<void>

Enhanced click function, supports continuous click for some expected result.

options

{
    x: 10,   // click on element offset left
    y: 10,   // click on element offset top

    forShow?: string | forHidden?: string | forDispose?: string | forExist?: string | forTarget?: string | until?: () => true // checking options, selector or sub string of url or function
    // should not be more than one of checking options

    // the below options could work, only if had one of above checking options
    timeout: 10000, // timeout
    timespan: 1000, // time span between two click
    delay: 100,  // delay of checking expected result after click
    closeTarget: true  // work with forTarget, close target when the target is open
}

VSelector.input(content: string, autoBlur: boolean = true): Promise<void>

  1. clear the old value of element
  2. type the new value to the element
  3. blur the element by default

VSelector.type(content: string): Promise<void>

VSelector.type == Puppeteer.Page.type

VSelector.focus(): Promise<void>

VSelector.focus == Puppeteer.Page.focus

Some helpful tool methods

reload(options?: NavigationOptions): Promise<Response>

findTarget(targetUrlSubstr: string): Promise<Target>

closeTarget(targetUrlSubstr: string): Promise<Target>

blur(): Promise<void>

setBrowser(browser: Browser): Promise<void>

setCurrentPage(page: Page): Promise<void>

page: Page // current page object

browser: Browser // current browser object

Constants

UNDEFINED, NULL, EMPTY, NOT_EMPTY

await $('div.dialog').waitFor.attr('id', $.constants.NOT_EMPTY)


puppeteer-toolkit is being revised and updated periodically

Welcome to be a contributor to this project



License

Licensed under MIT