Skip to content

Play

library

Browser automation with Playwright: starts Chromium and returns a Browser to drive it. `Play.start()` opens a new browser; every call gives an independent browser. Pages, elements, waits and failure handling are documented on Browser and Locator, including the selector syntax, which differs a little from `Sel`. Playwright only drives Chromium (the Chrome for Testing that the agent downloads), has no Firefox or Docker mode, and waits for elements to be ready before it acts on them. Use `Sel` when you need Firefox or Docker. Window size, headless mode and the default timeout come from the project's settings. Downloads go to the project's `.downloads` folder. The run's replay policy controls recording. Close what you open: `browser.close()` for one browser, `Play.close()` for all of them. After `Play.close()` the library no longer starts browsers.

  • Kind Library, a global in every script
  • Category Browser
  • Functions 3

Objects

Functions

  • start Browser Opens a new Chromium browser and returns it.
  • close self Closes every browser this library has opened (the same as calling `close()` on each of them).
  • sleep self Pauses the script for a number of whole seconds; fractions are cut off, so `Play.sleep(0.5)` does not sleep.
Play.start()→Browser

Opens a new Chromium browser and returns it. Fails with an error when the browser cannot be started, or when `Play.close()` has already been called.

Returns

Browser An open browser window with its tabs, driven by Selenium (`Sel.start()`) or Playwright (`Play.start()`).

Example

local browser = Play.start()
browser.navigate("https://example.com")
print(browser.locator("xpath=//h1").text())
browser.close()
Play.close()→self

Closes every browser this library has opened (the same as calling `close()` on each of them). From then on `Play.start()` raises an error and `Play.sleep()` does nothing. Safe to call more than once.

Returns

self chainable The library itself, so calls can be chained.
Play.sleep(seconds: number)→self

Pauses the script for a number of whole seconds; fractions are cut off, so `Play.sleep(0.5)` does not sleep. Returns at once when the library has been closed. Prefer waiting for a condition (`locator.wait`, `locator.exists`) to a fixed sleep.

Parameters

seconds number
Number of seconds to sleep

Returns

self chainable The library itself, so calls can be chained.