🎭 Playwright for Rust
Playwright is a rust library to automate Chromium, Firefox and WebKit built on top of Node.js library.
** This fork aims to provide a full compatibility with the latest driver (Playwright 1.57.0) and to fix issues found in the original repository. **
[dependencies]
playwright = { url = "https://github.com/sctg-development/playwright-rust", branch = "master" }
use playwright::Playwright;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize Playwright and install browsers if needed
let playwright = Playwright::initialize().await?;
playwright.prepare()?;
// Launch a headless Chromium browser
let chromium = playwright.chromium();
let browser = chromium.launcher().headless(true).launch().await?; // Use .headless(false) to see the browser
// Create a new browser context and page
let context = browser.context_builder().build().await?;
let page = context.new_page().await?;
// Navigate to the GitHub Pages documentation
page.goto_builder("https://sctg-development.github.io/playwright-rust/playwright/")
.goto()
.await?;
// Execute JavaScript to get the current URL
let url: String = page.eval("() => location.href").await?;
println!("Current URL: {}", url);
// Click on the API documentation link
page.click_builder(r#"a[title="mod playwright::api"]"#)
.click()
.await?;
// Extract the version number from the documentation page
let version: String = page
.eval(r#"() => document.querySelector("span.version").innerText.trim()"#)
.await?;
println!("Package version: {}", version);
// Verify we're on the correct page
assert_eq!(
page.url().unwrap(),
"https://sctg-development.github.io/playwright-rust/playwright/api/index.html"
);
// Clean up - browser context and page are automatically closed when dropped
browser.close().await?;
Ok(())
}These runtimes have passed tests. You can disable tokio, the default feature, and then choose another.
Functions do not have default arguments in rust. Functions with two or more optional arguments are now passed with the builder pattern.
Playwright is designed as a server-client. All playwright client dependent on the driver: zip of core js library and Node.js. Application uses this library will be bundled the driver into rust binary at build time. There is an overhead of unzipping on the first run.
playwright-rust redistributes Playwright licensed under the Apache 2.0.
Playwright has NOTICE:
"""
Playwright
Copyright (c) Microsoft Corporation
This software contains code derived from the Puppeteer project (https://github.com/puppeteer/puppeteer),
available under the Apache 2.0 license (https://github.com/puppeteer/puppeteer/blob/master/LICENSE).
"""