@@ -14,27 +14,55 @@ Playwright is a rust library to automate [Chromium](https://www.chromium.org/Hom
1414## Installation
1515```
1616[dependencies]
17- playwright = { url = "https://github.com/sctg-development/playwright-rust" branch = "master" }
17+ playwright = { url = "https://github.com/sctg-development/playwright-rust", branch = "master" }
1818```
1919
2020## Usage
2121``` rust
2222use playwright :: Playwright ;
2323
2424#[tokio:: main]
25- async fn main () -> Result <(), playwright :: Error > {
25+ async fn main () -> Result <(), Box <dyn std :: error :: Error >> {
26+ // Initialize Playwright and install browsers if needed
2627 let playwright = Playwright :: initialize (). await ? ;
27- playwright . prepare ()? ; // Install browsers
28+ playwright . prepare ()? ;
29+
30+ // Launch a headless Chromium browser
2831 let chromium = playwright . chromium ();
29- let browser = chromium . launcher (). headless (true ). launch (). await ? ;
32+ let browser = chromium . launcher (). headless (true ). launch (). await ? ; // Use .headless(false) to see the browser
33+
34+ // Create a new browser context and page
3035 let context = browser . context_builder (). build (). await ? ;
3136 let page = context . new_page (). await ? ;
32- page . goto_builder (" https://example.com/" ). goto (). await ? ;
3337
34- // Exec in browser and Deserialize with serde
35- let s : String = page . eval (" () => location.href" ). await ? ;
36- assert_eq! (s , " https://example.com/" );
37- page . click_builder (" a" ). click (). await ? ;
38+ // Navigate to the GitHub Pages documentation
39+ page . goto_builder (" https://sctg-development.github.io/playwright-rust/playwright/" )
40+ . goto ()
41+ . await ? ;
42+
43+ // Execute JavaScript to get the current URL
44+ let url : String = page . eval (" () => location.href" ). await ? ;
45+ println! (" Current URL: {}" , url );
46+
47+ // Click on the API documentation link
48+ page . click_builder (r # " a[title="mod playwright::api"]" # )
49+ . click ()
50+ . await ? ;
51+
52+ // Extract the version number from the documentation page
53+ let version : String = page
54+ . eval (r # " () => document.querySelector("span.version").innerText.trim()" # )
55+ . await ? ;
56+ println! (" Package version: {}" , version );
57+
58+ // Verify we're on the correct page
59+ assert_eq! (
60+ page . url (). unwrap (),
61+ " https://sctg-development.github.io/playwright-rust/playwright/api/index.html"
62+ );
63+
64+ // Clean up - browser context and page are automatically closed when dropped
65+ browser . close (). await ? ;
3866 Ok (())
3967}
4068```
0 commit comments