RFBrowser in Robot Framework

Introduction

RFBrowser is a new browser driver built into RobotFramework, based on Playwright

Installation

The command to install it using pip

python -m pip install robotframework-browser

An example of installing from scratch

python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install robotframework
python -m pip install robotframework-browser
rfbrowser init

Then you need to install nodejs version 12 or newer. For how to do this in Linux read in the article «Install the latest version of nodejs»

Launch the browser in visible mode

To run RFBrowser in visible mode you need to set the option headless=False

New Browser browser=chromium headless=False

xpath

# By class names Click xpath=//span[@class="name1 name2 name3"] # By url Wait For Elements State xpath=//a[@href="${your_url}"] visible

Example: Verifying the page title

*** Settings *** Documentation Example that opens single page Library Browser ... enable_playwright_debug=${True} ... auto_closing_level=TEST ... retry_assertions_for=0:00:03 *** Variables *** ${url} https://eth1.ru *** Keywords *** Start Chromium Browser New Browser browser=chromium headless=False New Context viewport={'width': 1920, 'height': 1080} ignoreHTTPSErrors=True *** Test Cases *** Starting a browser with a page Start Chromium Browser New Page https://eth1.ru Get Title == eth1.ru Close Browser

ElementState

All possible states an element can have.

Documentation

Allowed Values attached detached visible hidden enabled disabled editable readonly selected deselected focused defocused checked unchecked stable

Get Element States

Checking the state of an element now has to be done with the Get Element States keyword

For example, if you need to check the visibility of an element with the class devhops

*** Settings *** Documentation Example that opens single page Library Browser ... enable_playwright_debug=${True} ... auto_closing_level=TEST ... retry_assertions_for=0:00:03 *** Variables *** ${url} https://eth1.ru *** Keywords *** Start Chromium Browser New Browser browser=chromium headless=False New Context viewport={'width': 1920, 'height': 1080} ignoreHTTPSErrors=True Verify Element Visibility [Arguments] ${selector} ${visible} = Get Element States ${selector} then bool(value & visible) Should Be True ${visible} *** Test Cases *** Verify devhops Visibility Start Chromium Browser New Page https://eth1.ru Verify Element Visibility .devhops Close Browser

In this example we pass the selector argument to the Verify Element Visibility keyword.

You can read more about this in the article «Passing arguments»

Article author: Andrei Olegovich