Getting Started
Install the module, provision a browser, run your first script.
Getting Started
Install the module, download a browser and run a first script. Requires BoxLang 1.17+ and Java 21+.
Install
install-bx-module bx-playwright
bxplaywright install # driver + Node.js + Chromium
bxplaywright doctor # check everything
- More browsers:
bxplaywright install firefox webkit. - On Linux CI, add
--with-depsto also install the system libraries browsers need. - Everything is stored in
~/.boxlang/playwright. Change it with thehomesetting orBX_PLAYWRIGHT_HOME. bx-playwright-fullbundles Node.js for every platform, soinstallskips the Node.js download. Browsers are still downloaded unless they are already installed.
Deploy the module to that server and call playwrightEnsureBrowser( "chromium" ) from server code: no separate CLI install is needed. TestBox browser specs do this for you on first use. See BoxLang Web Applications and TestBox Browser Testing.
Browser download problems
- Browsers download from Playwright's CDN (
https://cdn.playwright.dev). Behind a proxy, setHTTPS_PROXYbefore runningbxplaywright install. - On a slow network, raise
PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT(milliseconds,120000by default), see Configuration. - To skip the Chromium download, use an installed Google Chrome with the
chromeprofile:playwright( "chrome" ). - Run
bxplaywright doctorto see what is installed and how to fix what is missing.
First script
// hello.bxs
playwright().browse( ( page ) => {
page.visit( "https://boxlang.io" )
println( page.title() )
page.screenshot( "boxlang.png" )
} )
boxlang hello.bxs
playwright() returns a manager and starts nothing until you use it. browse() opens a fresh page, runs your code and closes everything, even when the code throws.
Clean up
Prefer browse() and the one-shot helpers (screenshot(), pdf(), content(), render()): they close the browser for you. When you manage pages yourself, close them:
pw = playwright()
page = pw.newPage()
try {
page.visit( "https://boxlang.io" ).assertSee( "BoxLang" )
} finally {
pw.close()
}
page.close()closes the page and its context; the manager stays open.page.quit()orpw.close()closes everything: pages, contexts, browser and driver.- A manager is not thread safe: use it from the thread that created it.
Next
- Browsing: selectors, actions and locators.
- Assertions: checks that wait for the page.
- TestBox Browser Testing: browser specs with
@browser. - Automation Scripts: turn a script into a recorded, scheduled job.