The basic idea
In a nutshell, Robot Framework is a basic open-source framework for automated testing, aimed at acceptance testing for web apps used in a browser, or for API testing.
“Basic” here says nothing about what the framework can do. It means generic: the framework provides the most basic building blocks for testing.
Robot Framework's main job is to provide those building blocks so users can create and run their own automated test cases. That is why most Robot Framework libraries wrap existing, also-open-source frameworks:
SeleniumLibrarywraps Selenium and gives Robot Framework the ability to automate browser testing.AppiumLibrarywraps Appium and lets Robot Framework interact with an Appium server for automated testing on Android mobile devices.
And there are plenty of other libraries.
Strengths
- It is a KDT (Keyword Driven Testing) framework. Tests are easier to write, read and maintain. In practice, each test case is written as a sequence of actions that reads like English.
For example, Element Should Be Visible means checking whether an element is visible on a web page; if it is not, the keyword fails. The keyword wraps Selenium's is_displayed() function.
With Selenium and Python, a line like this is not immediately obvious unless you have Selenium's documentation open beside you:
assert element.is_displayed() == True
With Robot Framework, reading the keyword usually tells you what it is doing.
-
It can be extended with many libraries, not just Selenium and Appium, but also libraries for databases, APIs, SSH, and so on. I already mentioned this above.
-
It is open source. One useful thing about open source is that you can customise, change and extend it, and contribute back to the community. For example, with
Element Should Be Visible, you can find its source code and see which Selenium function it uses, so the keyword's behaviour is not magic. -
It can be structured using the Page Object model, which makes test cases easier to maintain. I will have a separate article on what Page Object Model actually is.
Typical question: What is Robot Framework?
Typical question: What types of testing frameworks are there?
Typical question: What is Keyword Driven Testing?
Selenium Library
In this blog's Robot Framework section, I will focus on SeleniumLibrary because browser automation is the easiest part to set up and demonstrate. The more interesting parts of Robot Framework will also be explained with SeleniumLibrary examples. If I have time, I may later look briefly at libraries such as Appium for mobile testing and RequestsLibrary for API testing.
SeleniumLibrary is one of Robot Framework's important libraries. It wraps Selenium and provides keywords for automated browser testing. That is why I want to use it throughout the Robot Framework articles: it covers the whole path, from writing scripts to reading logs and finding bugs.
First, SeleniumLibrary is just a library, meaning that it provides keywords. Those keywords wrap library functions, so under the hood Robot Framework is still using Selenium.
Selenium's structure
Selenium has four main parts:
- IDE: Selenium IDE records and runs test cases in a browser. It is only an extension. It is easy to use, but not particularly powerful.
- WebDriver: Selenium WebDriver is an API for interacting with a browser. It provides functions such as click, send_keys and find_element.
- Grid: Selenium Grid runs test cases across multiple browsers and devices at the same time, making execution faster.
- Remote Control: It has had its day and has been put out to pasture. Nobody uses it any more.
You can also consider Client API a fifth component, although it sits inside WebDriver and can be grouped there. WebDriver supports several programming languages, including Java, Python and JavaScript. If Robot Framework uses Python bindings to operate Selenium, those bindings are the Client API.
What can SeleniumLibrary do?
SeleniumLibrary basically helps us do what Selenium can do. Some example keywords are:
Open Browser: open a browser.Go To: navigate to a web page.Click Element: click an element.Input Text: enter data into an element.
There are also assertion keywords, such as:
Element Should Be Visible: check whether an element is visible.Element Text Should Be: check whether an element's text is what we expect.Title Should Be: check whether the page title is what we expect.
There are many more. I will go through some of them in later articles, but they are all in the documentation, so go and read SeleniumLibrary.
Typical question: What is Selenium Library?
Typical question: What are Selenium's components?
Typical question: What are some SeleniumLibrary keywords?