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

@autoflowlabs/playwright

v1.0.7

Published

Give superpowers to your playwright tests with AI

Downloads

116

Readme

GitHub stars GitHub forks

Npm package total downloads

Discord


AutoFlow

Add superpowers to your end-to-end tests with AutoFlow's open-source library. Learn more at https://autoflow.tools

Setup

1. Install the @autoflowlabs/playwright dependency

You can add the @autoflowlabs/playwright package to your project by executing the following command in your terminal:

Install Autoflow using yarn:

yarn add --dev @autoflowlabs/playwright @playwright/test

Or npm:

npm install -D @autoflowlabs/playwright @playwright/test

2. Setting up the API Key/Token

This library requires access to a specific environment variable that contains your AutoFlow token, which is essential for the playwright process. This token can be found in your account on https://autoflow.tools. You can expose this variable in various ways. One option is to set it as an environment variable, as demonstrated below:

$ export AUTOFLOW_TOKEN="<your token here>"

Alternatively, you can store this token in a configuration file named autoflow.config.json located in your project's root directory, structured like this:

{
  "TOKEN": "<your token here>"
}

3. Get Set Flow!

Utilize and incorporate the autoflow() function into your codebase by importing it as shown:

import { test } from "@playwright/test";
import { autoflow } from "@autoflowlabs/playwright";

test("autoflow example", async ({ page }) => {
  await page.goto("https://google.com/");

  // An object with page and test must be passed into every call
  const testArgs = { page, test };
  const searchButtonText = await autoflow("Get the search button text", testArgs);
  await page.goto("https://google.com/");
  await autoflow(`Type "${searchButtonText}" in the search box`, testArgs, {flowType: "action"});
  await autoflow("Press enter", testArgs, {flowType: "action"});
});

Usage

To employ the autoflow() function, you require a basic text prompt and an argument that includes yourpageand test objects.

Moreover, you can also specify a flowType, which presently includes support for action, query and assert.

autoflow("<your prompt>", { page, test }, {flowType: "action"});

Tip

The test invocations are cached for convenience to the users. If you're getting undesired results and want to invalidate the cache, use the cacheBypass option.

autoflow("<your prompt>", { page, test }, {cacheBypass: true});

Supported Browsers

The functionality provided by this package is limited to performing autoflow() actions exclusively within Chromium browsers.

Type of Flows

There are 3 types of flowType supported. If a flowType is not provided, it is inferred from the statement.

Example

  • With flowType
await autoflow("Click the link", { page, test }, {flowType: "action"});
  • With implicit flowType
await autoflow("Click the link", { page, test });

1. Action

Version: BETA

Return Type: undefined

An action, such as a "click," represents a simulated user interaction with the webpage, like clicking a link. If necessary, it will scroll to accomplish the designated task but prioritizes elements visible in the current viewport. Successful actions will return undefined, while failures will trigger an error, as shown below:

try {
  await autoflow("Click the link", { page, test }, {flowType: "action"});
} catch (e) {
  console.error("Failed to click the link");
}

Action prompts will result in one or multiple browser actions, including:

  • Clicking elements
  • Inputting text
  • Pressing the 'Enter' key
  • Navigating to a new URL

2. Query

Version: BETA

Return Type: string

A query will provide requested data from the visible section of the page as a string, for instance:

const linkText = await autoflow(
  "Get the text of the first link", { page, test }, {flowType: "query"});
console.log("The link text is", linkText);

3. Assert

Version: ALPHA

Return Type: bool

Assert will evaluate whether something exists on the page and return a true or false

const linkText = await autoflow(
  "Is there a dog on this page?", { page, test }, {flowType: "assert"});
console.log("The link text is", linkText);

It must be noted that the assert is more inclined towards how something looks or whether something is present on the page or not VS query is about how something reads.

Don't have tests yet? Test out AutoFlow on examples

Within this repository, there exists a demo allowing quick experimentation with the autoflow() function. To begin using it, follow these steps:

  1. Build the local version of the @autoflow/playwright package.
cd packages/playwright
npm install
npm run build
  1. Install the @autoflow/playwright dependency within the examples directory.
cd ../../examples/playwright
npm install
  1. Make the AUTOFLOW_TOKEN environment variable or configuration value accessible (refer to the "Setup" section above).

  2. Run the tests, with or without UI mode

Without UI Mode

$ npm run test

With UI Mode

$ npm run test-ui

This is an alias for npx playwright test --ui

Tips

  • If the Chromium binary is not already installed, utilize the following command to install the necessary browsers.
$ npx playwright install
  • To ensure your prompts function correctly, here are recommended best practices for Autoflow AI prompts

    • Construct prompts using complete English sentences. Minute grammatical errors are allowed but should be avoided
    • Enclose any text that should display precisely as stated within quotation marks. For instance, Click on the "Login" button
    • Avoid incorporating CSS/XPath selectors or any implementation-level specifics in your prompts.
    • Create prompts that match your specific needs. Having a bit of uncertainty can be okay and sometimes even preferred. For instance, a prompt like Find and click the "Learn More" button remains effective even if there are multiple buttons with that label or if the page has undergone a complete redesign.
    • A single prompt should have a single instruction. Avoid merging multiple instructions within a single prompt. For instance, refrain from phrases like 'Type in the "Search bar" and then click on the "Menu"'. Instead, ensure that each prompt distinctly focuses on one action or query.

Testing Limitations in Free Tier

In our commitment to offer a generous free tier to maximum users possible, we support sequential test runs only. For optimal performance, kindly run tests using the following commands:

Headless tests: npx playwright test --workers=1 Tests with a graphical user interface: npx playwright test --ui --workers=1

At AutoFlow, we're committed to delivering a top-tier experience to the community by leveraging cutting-edge technology. With this vision in mind, we've fine-tuned our systems and services to accommodate a high volume of parallel connections and testing, ensuring that everyone enjoys a seamless and efficient experience.

GitHub stars