Robot Framework Selenium: Browser Testing With SeleniumLibrary
Robot Framework Selenium testing with SeleniumLibrary: installation, first browser test, locator strategies, waits, headless CI runs and Browser library comparison.
Read article
Robot Framework tutorial content often jumps straight into browser automation, but the fastest way to learn is to start with a tiny suite that runs in seconds. This walkthrough covers installation, file structure, keywords, variables and reports, giving you a working mental model before you add any external libraries.
Robot Framework runs on Python, so the only hard requirement is a Python 3 interpreter supported by the release you install. A code editor with syntax highlighting makes the tabular format much easier to read, and a terminal is needed to run the robot command and open the generated results.
Create a virtual environment inside your project folder, activate it and install the package with pip. Keeping each project in its own environment prevents version clashes between libraries and makes it simple to reproduce the setup on a colleague’s machine or a CI runner.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install robotframework
robot --version
If robot --version prints a version string, the installation worked. Detailed platform notes, including PATH fixes for Windows, are covered in the installation walkthrough for Windows, macOS and Linux.
Test data lives in files with the .robot extension. Each file is a test suite, and a folder of .robot files becomes a parent suite automatically. Inside a file, content is split into sections that start with three asterisks on both sides of the section name.
| Section | Purpose |
|---|---|
| *** Settings *** | Imports libraries and resources, sets documentation, setups and teardowns |
| *** Variables *** | Defines reusable values such as URLs, timeouts and user names |
| *** Test Cases *** | Holds the executable tests, each built from keyword calls |
| *** Keywords *** | Creates user keywords that combine other keywords into reusable steps |
Cells are separated by two or more spaces, and four spaces is the common convention. Test case and keyword names start at the beginning of a line, while their steps are indented. A single space is treated as part of a value, which is why “Should Be Equal” works as one keyword name.
Create a file called first_suite.robot and add the following content. It uses only BuiltIn keywords, which are always available, so no extra library installation is required for this example.
*** Settings ***
Documentation My first suite.
*** Variables ***
${GREETING} Hello, Robot
*** Test Cases ***
Greeting Is Correct
${text}= Set Variable Hello, Robot
Should Be Equal ${text} ${GREETING}
Log Test finished
Number Comparison Works
${sum}= Evaluate 2 + 3
Should Be Equal As Integers ${sum} 5
Each indented line calls a keyword followed by its arguments. Set Variable returns a value that is stored in ${text}, and Should Be Equal fails the test if its two arguments differ. More patterns like these appear in the collection of practical Robot Framework examples.
Run the suite from the project folder with robot first_suite.robot. The console shows each test with a PASS or FAIL status, followed by a summary line and the paths of three result files written to the current directory.
Open log.html in a browser whenever a test fails. Expanding the failing test shows the exact keyword that raised the error and the message it produced, which is usually enough to locate the problem quickly.
User keywords keep tests short by moving repeated steps into named building blocks. They are defined in the Keywords section, can accept arguments and can return values, so a test reads like a list of business actions rather than low-level instructions.
*** Keywords ***
Greeting Should Match
[Arguments] ${actual}
Should Be Equal ${actual} ${GREETING}
Once a project grows, move shared keywords into a .resource file and import it with the Resource setting. The deeper explanation of built-in, library and user keywords is available in the Robot Framework keywords overview.
Tags label tests so you can run subsets with --include or --exclude. Setup and teardown keywords prepare and clean the environment, and a teardown still runs when the test fails, which makes it the right place for closing browsers or deleting temporary data.
Greeting Is Correct
[Tags] smoke
[Setup] Log Preparing
Greeting Should Match Hello, Robot
[Teardown] Log Cleaning up
With the core syntax in place, most learners move to a real application. Web testers usually continue with Robot Framework Selenium, while developers often learn how to write custom keywords in Python libraries for logic that would be awkward in test data.
Basic syntax can be learned in a few hours because tests are mostly keyword calls. Becoming productive with libraries, resource files and project structure usually takes a few weeks of regular use on a real project.
No programming experience is required to write and run tests with existing keywords. Python knowledge becomes useful later, when you want to create custom libraries or handle complex logic outside the test data.
Yes. The examples in this tutorial use only BuiltIn keywords and run entirely in the terminal. Browser libraries are optional and only needed for web user interface testing.
After the first successful run, deliberately change an expected value and run the same suite again. Open the HTML log, expand the failing keyword and compare the reported actual and expected values. Restore the original expectation and confirm the suite passes. Repeat this exercise when introducing a new library so you understand what evidence its keywords leave in the log when an assertion fails or setup cannot finish. Save both logs for your initial review.
Robot Framework tutorial steps like these give you a solid base: install with pip, structure suites into sections, write tests from keywords, run them with robot and read the log. Practise by turning a few manual checks from your own project into small suites, then add libraries as real needs appear.