04 · Web UI with Browser
Install Browser Library correctly, apply Playwright-style isolation, locators, assertions and evidence.
Installation routes
Current Browser Library supports a bundled Node runtime (python -m pip install 'robotframework-browser[bb]' then rfbrowser install) and the external Node.js route (python -m pip install robotframework-browser then rfbrowser init). These are alternatives, not consecutive steps. Use a fresh context for each test, stable locators and state-based assertions.
Browser Library: web automation foundation
Use the Playwright-backed Browser Library with explicit browser lifecycle and strong locators.
Browser Library is a modern web-automation library built on Playwright. It is separate from Robot core.
# Bundled Node runtime (recommended on supported platforms):
python -m pip install "robotframework-browser[bb]"
rfbrowser install
# OR bring your own supported Node.js:
python -m pip install robotframework-browser
rfbrowser initA minimal suite:
*** Settings ***
Library Browser
*** Test Cases ***
Robot Framework Browser Site Opens
New Browser chromium headless=${True}
New Context
New Page https://robotframework-browser.org
Get Title *= Robot Framework Browser
Take Screenshot
Close BrowserRun it:
python -m robot --outputdir results browser.robotThink in three lifecycle levels: Browser process, Context, Page. A context isolates cookies/storage and is often the right unit for test isolation. A page is a tab.
Prefer locators based on stable user-facing semantics or dedicated test IDs over brittle DOM structure. Browser Library supports CSS and other selector engines; choose locators that describe the element's identity rather than its incidental position.
SeleniumLibrary also exists and is mature. Choose based on the existing project, browser requirements and team ecosystem. For a new Robot web suite, Browser Library is often the more direct route to Playwright capabilities.
Key points
- Browser, Context and Page are distinct lifecycle objects
- Use
rfbrowser installwith BrowserBatteries orrfbrowser initwith external Node.js - Prefer stable semantic/test-id locators
Common pitfalls
- Treating Browser Library like Selenium and carrying over manual-wait and locator habits unchanged
Browser assertions, waiting and page-level keywords
Build stable UI tests around retried assertions rather than sleeps.
Browser Library's waiting model is one of its most important features. Many getters become retrying assertions when you pass an assertion operator. Without an operator they read once.
Get Text css=.status == ReadyThe line above retries according to the assertion timeout. This line does not:
${status}= Get Text css=.statusFor conditions that are not naturally covered by a getter assertion, use Wait For Condition or Wait For Function. Avoid fixed Sleep except when the delay itself is what you are testing.
Put low-level selectors and mechanics into page/component keywords:
*** Keywords ***
Login As
[Arguments] ${username} ${password}
Fill Text id=username ${username}
Fill Secret id=password $password
Click role=button[name="Sign in"]
Get Url *= /dashboardThen tests can stay at the domain level. Keep assertions close to the behavior they verify. A page keyword may assert that a transition completed when that postcondition is intrinsic to the action; broader business assertions should remain visible in the test.
When a failure occurs, inspect Browser traces/screenshots together with Robot log.html. Evidence should explain both the Robot keyword flow and the browser state.
Key points
- Getter plus assertion operator is also a synchronization primitive
- Encapsulate selectors in page/component keywords
- Prefer state-based waits over time-based sleeps
Common pitfalls
- Reading once and immediately asserting later when a retrying getter assertion would be stable
Browser contexts, cleanup and secret input
Connect UI isolation, stable selectors and secret-handling rules.
A Browser context isolates cookies and storage, while a page is only a tab. Creating another page inside an existing context is not isolation. Ensure teardown closes the context even when assertions fail.
Context-per-test pattern (illustrative; requires Browser Library)
*** Settings ***
Library Browser
Test Setup Open Isolated Page
Test Teardown Close Context
*** Keywords ***
Open Isolated Page
New Browser chromium headless=${True}
New Context
New Page https://robotframework-browser.org
*** Test Cases ***
Site Is Reachable
Get Title *= Robot Framework BrowserFor real projects, a suite-owned browser process with one test-owned context is more efficient; ensure there is a browser available before New Context and close the correct context in teardown. Fill Secret does not accept an ordinary ${password} variable; use a Robot Secret or the $password/%PASSWORD indirection. Avoid Playwright DEBUG traces containing credentials.
Use retried getter assertions instead of Sleep; capture a screenshot before closing a failed context and restrict artifact access.
Key points
- A fresh page does not isolate browser storage
- Secret keywords and artifacts have different disclosure risks
Common pitfalls
- Creating a new browser for every step or reusing one logged-in context across tests