robotframework-browser
Robot Framework Browser library powered by Playwright. Moving browser automation to year 2023!
Aiming for
See keyword documentation and web page for more details.
Installation instructions
Only Python 3.7 or newer is supported.
- Install node.js e.g. from https://nodejs.org/en/download/
- Update pip
pip install -U pip
to ensure latest version is used - Install robotframework-browser from the commandline:
pip install robotframework-browser
- Install the node dependencies: run
rfbrowser init
in your shell
- if
rfbrowser
is not found, trypython -m Browser.entry init
Please note that by default Chromium, Firefox and WebKit browser are installed, even those would be already
installed in the system. The installation size depends on the operating system, but usually is +700Mb.
It is possible to skip browser binaries installation with rfbrowser init --skip-browsers
command, but then user
is responsible for browser binary installation.
Or use the docker images. Documented at docker/README.md.
Update instructions
To upgrade your already installed robotframework-browser library
- Update from commandline:
pip install -U robotframework-browser
- Clean old node side dependencies and browser binaries:
rfbrowser clean-node
- Install the node dependencies for the newly installed version:
rfbrowser init
Uninstall instructions
To completely install library, including the browser binaries installed by Playwright, run following commands:
- Clean old node side dependencies and browser binaries:
rfbrowser clean-node
- Uninstall with pip:
pip uninstall robotframework-browser
Examples
Robot Framework
Testing with*** Settings ***
Library Browser
*** Test Cases ***
Example Test
New Page https://playwright.dev
Get Text h1 contains Playwright
Python.
and testing withimport Browser
browser = Browser.Browser()
browser.new_page("https://playwright.dev")
assert 'Playwright' in browser.get_text("h1")
browser.close_browser()
and extending with JavaScript
async function myGoToKeyword(url, page, logger) {
logger("Going to " + url)
return await page.goto(url);
}
myGoToKeyword.rfdoc = "This is my own go to keyword";
exports.__esModule = true;
exports.myGoToKeyword = myGoToKeyword;
*** Settings ***
Library Browser jsextension=${CURDIR}/mymodule.js
*** Test Cases ***
Example Test
New Page
myGoToKeyword https://www.robotframework.org
See example. Ready made extensions and a place to share your own at robotframework-browser-extensions.
text
, css
and xpath
selectors
Ergonomic selector syntax, supports chaining of # Select element containing text "Login" with text selector strategy
# and select it's parent `input` element with xpath
Click "Login" >> xpath=../input
# Select element with CSS strategy and select button in it with text strategy
Click div.dialog >> "Ok"
Evaluate in browser page
New Page ${LOGIN_URL}
${ref}= Get Element h1
Get Property ${ref} innerText == Login Page
Evaluate JavaScript ${ref} (elem) => elem.innerText = "abc"
Get Property ${ref} innerText == abc
Asynchronously waiting for HTTP requests and responses
# The button with id `delayed_request` fires a delayed request. We use a promise to capture it.
${promise}= Promise To Wait For Response matcher= timeout=3s
Click \#delayed_request
${body}= Wait For ${promise}
Device Descriptors
${device}= Get Device iPhone X
New Context &{device}
New Page
Get Viewport Size # returns { "width": 375, "height": 812 }
Sending HTTP requests and parsing their responses
&{response}= HTTP /api/post POST {"name": "John"}
Should Be Equal ${response.status} ${200}
Parallel test execution using Pabot
You can let RF Browser spawn separate processes for every pabot process. This is very simple, just run the tests normally using pabot (see https://github.com/mkorpela/pabot#basic-use ). However if you have small tests do not use --testlevelsplit
, it will cause lots of overhead because tests cannot share the browsers in any case.
You can share the node side RF Browser processes by using the ROBOT_FRAMEWORK_BROWSER_NODE_PORT
environment variable, and from Browser.utils import spawn_node_process
helper (see the docs for the helper ). This saves some overhead based on how many splits of tests you are running. Clean up the process afterwards.
Re-using authentication credentials
- Figure out how the page is storing authentication
- If it is localstorage or cookies
Save Storage State
should work. See usage example: https://marketsquare.github.io/robotframework-browser/Browser.html#Save%20Storage%20State
Development
See CONTRIBUTING.md for development instructions.
Core team
In order of appearance.
- Mikko Korpela
- Tatu Aalto
- Janne Hรคrkรถnen (Alumnus)
- Kerkko Pelttari
- Renรฉ Rohner
Contributors
This project is community driven and becomes a reality only through the work of all the people who contribute. Supported by Robocorp through Robot Framework Foundation.