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

playword

v1.1.0

Published

PlayWord lets you effortlessly write web automation tests in natural language, making testing more intuitive and accessible!

Downloads

507

Readme

PlayWord

NPM Version Release Notes CI GitHub License

Convert your intentions into Playwright actions with AI!

📦 Installation

Install playword package with any package manager you prefer.

npm  add playword
yarn add playword
pnpm add playword

🚀 Usage

Using PlayWord is very simple!

First, this package requires calling OpenAI API. You need to export your API key as an environment. You can see more details on how to get the API key here.

export OPENAI_API_KEY="sk-..."

💬 Talk with Browser

After setting up the API key, import this package and use it as shown below.

import { chromium } from 'playwright'
import { PlayWord } from 'playword'
;(async () => {
  const browser = await chromium.launch()
  const page = await browser.newPage()

  const playword = new PlayWord(page)

  await playword.say('Navigate to https://www.google.com')

  await playword.say('Input "Hello, World" in the search field')

  await playword.say('Press Enter')
})()

No need to worry about how to locate elements or how to interact with them. PlayWord will take care of that for you!

Multiple actions in one sentence

When you include multiple actions in one sentence, PlayWord will execute them in parallel.

NOTE: Since it is not possible to determine which step will be executed first, please use multiple actions only under the premise that the order of execution does not matter.

await playword.say('Navigate to https://www.google.com')

await playword.say('Input "Hello" in the search field and then input "World" in the search field')

await playword.say('Press Enter')

🧪 Assertion

PlayWord supports assertions as well!

Calling the say() method witn sentences that start with specific keywords will be treated as assertions.

import { test, expect } from '@playwright/test'
import { PlayWord } from 'playword'

test('An example of using PlayWord in a Playwright test', async ({ page }) => {
  const playword = new PlayWord(page)

  await playword.say('Navigate to https://www.google.com')

  await playword.say('Input "Hello, World" in the search field')

  await playword.say('Press Enter')

  const result = await playword.say('Check if the page contains "HELLO WORLD"')
  expect(result).toBe(true)
})

Assertion keywords

Keyword matching is used to determine if a step is an assertion, as it provides more stable results than AI judgment.

When a sentence starts with any of the following keywords, the intent is judged as an assertion: (case insensitive)

  • assert
  • assure
  • check
  • compare
  • confirm
  • ensure
  • expect
  • guarantee
  • is
  • match
  • satisfy
  • should
  • test
  • then
  • validate
  • verify

🔴 Recordings

PlayWord supports recording your tests and replaying them later.

When setting record to true, PlayWord will record the execution and save it in .playword/recordings.json as default.

const playword = new PlayWord(page, { record: true })
// save recordings in .playword/recordings.json

You can set a custom path as well. (Should end with .json)

const playword = new PlayWord(page, { record: 'path/to/recordings.json' })
// save recordings in path/to/recordings.json

When the recording is complete and the test is run again in record mode, PlayWord will use the execution records from the recording for sentences that have the same content and order. If there are changes in order or content, it will switch back to using AI execution.

Disable record mode for a specific step

If you don't want to use the recording in some steps, you can disable it by setting the withoutRecordings option to true.

await playword.say('Navigate to https://www.google.com', { withoutRecordings: true })

Customizing Endpoint for OpenAI API

Pass the baseURL and the apiKey to PlayWord options to connect to a custom endpoint. You can also set other OpenAI options with this method.

const playword = new PlayWord(page, { apiKey: '...', baseURL: 'https://<custom-endpoint>' })

Supported browsers

PlayWord supports any browser that Playwright supports.

Supported actions in PlayWord

Currently, PlayWord supports the following actions:

Browser actions

  • Click on an element
  • Hover over an element
  • Input text in an element
  • Navigate to a URL
  • Press keys
  • Scroll on the page
  • Select an option
  • Wait for a specific text to appear

Assertion

  • Assert the content of an element is equal to a specific text
  • Assert the element is visible
  • Assert the element is not visible
  • Assert the page contains a specific text
  • Assert the page does not contain a specific text
  • Assert the page title is equal to a specific text
  • Assert the URL matches a specific format (regexp)

More actions will be supported in the future!

🎉 Hope you enjoy using PlayWord!