Home  Python   How to use ...

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:

👉 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:


✅ Step 3: Verify Installation

Run:

robot --version

and

rfbrowser --help

Both should work without error.


🧠 3️⃣ Basic Concepts

TermDescription
BrowserA Playwright browser instance (e.g., Chrome, Firefox)
ContextAn isolated environment (like an incognito tab)
PageA single browser tab
Auto-waitWaits 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

KeywordPurpose
New BrowserLaunches browser (chromium, firefox, webkit)
New ContextCreates isolated session (like incognito)
New PageOpens a new tab or page
ClickClicks element
Fill TextFills input field
Get TextReads element text
Get TitleGets page title
Close BrowserCloses everything
Wait For Elements StateWaits 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:

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

FeatureBrowser (Playwright)SeleniumLibrary
EnginePlaywrightSelenium WebDriver
Auto-wait✅ Built-in❌ Manual
Parallel tests✅ Easy with contexts⚠️ Requires setup
Browser drivers❌ Not needed✅ Needed
Cross-browserChromium, Firefox, WebKitChrome, 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

CategoryDetail
LibraryBrowser (Playwright-based)
Command to Installpip install robotframework-browser
Init Commandrfbrowser init
Browsers SupportedChromium, Firefox, WebKit
Parallel ExecutionSupported via contexts
Best ForModern, dynamic web automation
ReportsHTML log/report generated by Robot Framework

Published on: Oct 19, 2025, 08:49 AM  
 

Comments

Add your comment