How to use playwright browser library with Robot Framework
Let’s go step-by-step through using the Browser Library with Robot Framework, which is the modern alternative to SeleniumLibrary.
🌐 Robot Framework Browser Library — Full Guide
🚀 1️⃣ What is Browser Library?
Browser Library is a modern web automation library for Robot Framework built on top of Microsoft Playwright (not Selenium).
It allows you to automate Chromium, Firefox, WebKit, and Edge browsers with:
- Faster execution
- Auto-wait for elements
- Headless or headed modes
- Better error handling and trace logs
👉 It’s the official Robot Framework Browser maintained by the Robot Framework Foundation.
⚙️ 2️⃣ Installation Steps
🧩 Step 1: Install Node.js
Playwright (used internally by Browser Library) requires Node.js. Download and install from https://nodejs.org
Verify installation:
node -v
npm -v
🧩 Step 2: Install Robot Framework and Browser Library
pip install robotframework-browser
Then initialize the library (downloads browsers + dependencies):
rfbrowser init
This command will:
- Install Playwright browsers (Chromium, Firefox, WebKit)
- Configure them for Robot Framework use
✅ Step 3: Verify Installation
Run:
robot --version
and
rfbrowser --help
Both should work without error.
🧠 3️⃣ Basic Concepts
| Term | Description |
|---|---|
| Browser | A Playwright browser instance (e.g., Chrome, Firefox) |
| Context | An isolated environment (like an incognito tab) |
| Page | A single browser tab |
| Auto-wait | Waits automatically for elements to be visible/enabled before acting |
🧪 4️⃣ Example Test Case
Create a file: tests/browser_example.robot
*** Settings ***
Library Browser
*** Variables ***
${URL} https://example.com
*** Test Cases ***
Open Example Page And Verify Title
New Browser chromium
New Context
New Page ${URL}
Get Title == Example Domain
Close Browser
🧩 5️⃣ Key Browser Library Keywords
| Keyword | Purpose |
|---|---|
New Browser | Launches browser (chromium, firefox, webkit) |
New Context | Creates isolated session (like incognito) |
New Page | Opens a new tab or page |
Click | Clicks element |
Fill Text | Fills input field |
Get Text | Reads element text |
Get Title | Gets page title |
Close Browser | Closes everything |
Wait For Elements State | Waits for element visibility/enabled state |
🧪 6️⃣ Example — Login Test
*** Settings ***
Library Browser
*** Variables ***
${URL} https://example.com/login
${USERNAME} test_user
${PASSWORD} mypass123
*** Test Cases ***
Login Test
New Browser chromium headless=${False}
New Context
New Page ${URL}
Fill Text input[name="username"] ${USERNAME}
Fill Text input[name="password"] ${PASSWORD}
Click button[type="submit"]
Wait For Elements State text=Welcome visible
Get Text h1 == Welcome
Close Browser
🧰 7️⃣ Advanced Features
▶️ a) Headless or Headed Mode
New Browser chromium headless=${False}
▶️ b) Screenshots
Take Screenshot filename=results/screenshot.png
▶️ c) Multiple Tabs (Pages)
New Page https://softpost.org
New Page https://openai.com
Switch Page https://softpost.org
▶️ d) Parallel Testing
Each test case can launch its own browser context for true parallelism.
📊 8️⃣ Running Tests
robot tests/browser_example.robot
Results will generate:
log.htmlreport.htmloutput.xml
Example:
==============================================================================
Tests.Browser Example
==============================================================================
Open Example Page And Verify Title | PASS |
------------------------------------------------------------------------------
Tests.Browser Example | PASS |
1 test, 1 passed, 0 failed
==============================================================================
🧩 9️⃣ Compare with SeleniumLibrary
| Feature | Browser (Playwright) | SeleniumLibrary |
|---|---|---|
| Engine | Playwright | Selenium WebDriver |
| Auto-wait | ✅ Built-in | ❌ Manual |
| Parallel tests | ✅ Easy with contexts | ⚠️ Requires setup |
| Browser drivers | ❌ Not needed | ✅ Needed |
| Cross-browser | Chromium, Firefox, WebKit | Chrome, Firefox, Edge, Safari |
| Speed | ⚡ Faster | 🐢 Slower |
| Trace & Debug | ✅ Excellent | ⚠️ Limited |
🧠 10️⃣ Debugging and Tracing
Enable tracing to capture screenshots, steps, and console logs:
*** Settings ***
Library Browser
Suite Setup Start Tracing
Suite Teardown Stop Tracing results/trace.zip
After test run, open the trace:
rfbrowser show-trace results/trace.zip
This will open an interactive UI showing each step, DOM snapshot, and screenshot (similar to Playwright trace viewer).
💡 11️⃣ When to Use Browser Library
✅ Modern web apps (React, Angular, Vue) ✅ Rich AJAX or dynamic content ✅ Parallel tests or cloud execution ✅ CI/CD pipelines where speed matters
🧮 12️⃣ Summary
| Category | Detail |
|---|---|
| Library | Browser (Playwright-based) |
| Command to Install | pip install robotframework-browser |
| Init Command | rfbrowser init |
| Browsers Supported | Chromium, Firefox, WebKit |
| Parallel Execution | Supported via contexts |
| Best For | Modern, dynamic web automation |
| Reports | HTML log/report generated by Robot Framework |