Skip to main content

Simple and efficient compagnion tool for Playwright. Write reusable and maintainable E2E tests like a human.

Project description

Playwright! Playsmart!

End the never ending game of having to manually record, inspect, and update your E2E tests with Playwright.

This chunk of code[...]

page.locator("#dkDj87djDA-reo").fill("hello@world.tld")
page.locator("#dflfkZkfAA-reo").fill("$ecr!t")
page.get_by_role("button", name="Log In").click()

will become

from playsmart import Playsmart

smart_hub = Playsmart(
    browser_tab=page,
)

with smart_hub.context("login page"):
    smart_hub.want("fill email input with hello@world.tld")
    smart_hub.want("fill password input with $ecr!t")
    smart_hub.want("click on login")

nicer, isn't it?

Get started!

Install Playsmart via PyPI

pip install playsmart

requires Python 3.10+

Before you get started, either:

  • export OPENAI_API_KEY
  • or set openai_key=... parameter within Playsmart class constructor.

Here's the minimum runnable example:

from playwright.sync_api import sync_playwright
from playsmart import Playsmart

driver = sync_playwright().start()
chrome = driver.chromium.launch(headless=False)
page = chrome.new_page()

page.goto("https://huggingface.co/docs")

smart_hub = Playsmart(
    browser_tab=page
)

with smart_hub.context("docs page"):
    smart_hub.want("click on PEFT doc section")

Caching

We know how painful consuming needlessly tokens can be. That's why Playsmart have a tiny caching layer that helps with keeping LLM hints.

You may at any moment disable the cache for a specific instruction as:

smart_hub.want("click on PEFT doc section", use_cache=False)

A discrete file, named .playsmart.cache will be created. You are encouraged to share this file across your teams! Commit it!

You may choose a filename at your own convenience via the cache_path=... parameter within the Playsmart class constructor.

The 'want' method in a nutshell

Basically, everything revolve around Playsmart.want(...) as you would have already guessed.

There's two types of action you can execute:

A) Immediate action: e.g. I want to click on something B) Deferred action: e.g. How many orders are marked as 'pending'?

For the case A) you should never expect the method to return anything (aside from empty list).

Finally, for the case B) Playsmart will always translate your query to a (or many) usable playwright.Locator.

Here is a solid example for B):

with smart_hub.context("dashboard"):
    locators = smart_hub.want("how many orders are labelled as 'pending'?")

    print(f"we have {locators[0].count()} order(s) pending")

Yet, another one:

with smart_hub.context("dashboard"):
    locators = smart_hub.want("list every fields in the form")

    for locator in locators:
        ... # your logic for each 'input<text/select/...>'

Debug runtime

If you are asking yourself "How did we arrive at that result?", use the handy function context_debug.

from playsmart import context_debug, Playsmart

smart_hub = Playsmart(
    browser_tab=...
)

with context_debug():
    smart_hub.want("click on PEFT doc section")

It will stream a list of detailed events to help you debug your test.

Disclaimer

This (heuristic) software is still at an early stage and has not been battle tested (yet). Although we envision a great future for it, it would be unwise to replace your entire E2E suite with it.

We encourage its incremental adoption and positive feedbacks to help us improve this.

Finally, note that the library is not thread safe.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playsmart-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playsmart-0.1.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file playsmart-0.1.0.tar.gz.

File metadata

  • Download URL: playsmart-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for playsmart-0.1.0.tar.gz
Algorithm Hash digest
SHA256 29a0556a911c53da2797d206c59702cc5b8b6b0bc2f99676db9b28a99449ea14
MD5 5871bc0869f7a49f6a6fc34ea5894a73
BLAKE2b-256 c1a60be7bb53d275c302f79abb7f8bd5a311c40c21dcbff08314ce240f792561

See more details on using hashes here.

File details

Details for the file playsmart-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: playsmart-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for playsmart-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5ef85586dfc101712c78148b39f656614e69cdee22dc9c9aca3c18cb9bed89f
MD5 540ad77110a60be0e1d257004d6cfc4b
BLAKE2b-256 e5c8c8473e245be0f5b1c1520eb43cc97263fda50c1bbc2382607aa1ad51690c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page