Robot Framework
- Summary
-
Discussion
- What are the benefits of using Robot Framework?
- What are the main features of Robot Framework?
- Could you list some built-in keywords used in Robot Framework?
- Where does Robot Framework fit within a test automation architecture?
- Could you share some best practices when writing tests in Robot Framework?
- What are some useful resources and tools for Robot Framework?
- Milestones
- Sample Code
- References
- Further Reading
- Article Stats
- Cite As
Robot Framework is a framework that automates acceptance testing and acceptance test-driven development. Being generic in nature, the framework can also be used to automate business processes, often called Robotic Process Automation (RPA).
The core of Robot Framework is written in Python but libraries extending it can be in Python or Java. The framework is independent of operating system and application. It's open source and is sponsored by the Robot Framework Foundation.
Test cases in Robot Framework are written using keywords. Keywords themselves are abstracted away from their implementation. This promotes reuse of keywords across tests and easier maintenance of tests, particularly in large projects.
Discussion
-
What are the benefits of using Robot Framework? Since Robot Framework is keyword-driven, it has the benefit of separating high-level descriptions of tests from the low-level implementation details. Test writers may not be programmers. Since keywords are closer to English than programming, test writers find it easier to write and maintain tests. Keywords can be reused across tests.
Tests are easy to read since they often take a tabular form. In this form, the first column contains keywords. Other columns contain arguments to each keyword. For example, "Create User" is a keyword that takes username and password as arguments. When implemented, this can translate to launching a web browser, clicking a button, entering the data, and confirming the request to create a new user.
Keywords are composable. This means that keywords themselves can depend on other keywords. This allows us to create tests at different levels of abstraction.
Since implementation is kept separate, test cases can be developed agnostic of any programming language. Testing can be planned at an early stage even before any implementation is ready.
-
What are the main features of Robot Framework? While keyword-driven tests are common, Robot Framework can also be used to create data-driven and behaviour-driven tests. It can also be used for automating any business process, and thus not limited to testing.
Test cases can be organized into test suites. Execution can be based on test suites, test cases, or tags, all of which can be specified by name or pattern. Test suites and test cases can have setup and teardown.
The framework produces neat reports and logs. It also allows for debugging.
Developers can extend the framework with their own keywords and libraries.
Test cases can be created in a single text file but they can also be created within the Robot Framework IDE (RIDE). Some popular IDEs can integrate with the framework including PyCharm, RED (Robot Editor) for Eclipse, and Robot Framework Intellisense for VS Code.
-
Could you list some built-in keywords used in Robot Framework? Online documentation gives complete descriptions of all built-in keywords along with accepted arguments. We list a few of them:
- Conditionals: Keyword Should Exist, Length Should Be, Should Be Empty, Should Be Equal, Should Contain, Variable Should Exist
- Control Flow: Continue For Loop, Exit For Loop, Repeat Keyword, Return From Keyword
- Conversions: Convert to Binary, Convert to Boolean, Convert to Bytes, Convert to Integer
- Executions: Call Method, Evaluate, No Operation, Run Keyword
- Library: Get Library Instance, Import Library, Reload Library, Set Library Search Order
- Logging: Log, Log Many, Log To Console, Log Variables, Set Log Level, Set Test Message
- String Operations: Catenate, Should End With, Should Match, Should Match Regexp, Should Not Be Equal As Strings
- Timing: Get Time, Run Keyword If Timeout Occurred, Sleep, Wait Until Keyword Succeeds
- Variables: Get Variable Value, Import Variables, Set Global Variable, Set Suite Variable, Set Test Variable
- Verdict: Fail, Fatal Error, Pass Execution, Pass Execution If
-
Where does Robot Framework fit within a test automation architecture? The job of the framework is to read and process data, execute test cases, and generate reports and logs. The core of the framework doesn't know anything about the system under test (SUT). Actual interaction with SUT is handled by various libraries. Libraries themselves rely on application interfaces or low-level test tools to interact with SUT.
Let's take the example of testing a web application. Suppose Selenium is used for testing the application. Robot Framework doesn't directly control interactions with the web browser or databases. SeleniumLibrary and DatabaseLibrary are two libraries that manage these interactions. These libraries expose relevant keywords that can be used in test cases without worrying about how they are implemented.
-
Could you share some best practices when writing tests in Robot Framework? Test cases should be easy to understand. Use descriptive names for test suites and test cases. Likewise, keyword names should clear and descriptive. A common convention is to use title case for keywords. For example, use
Input Text
rather thanInput text
. For variables, use lowercase for local scope and uppercase for global scope.Document each test suite. Describe the purpose of tests in that suite and the execution environment. Include links to external documents. At test case level, documentation may not be required. The use of suitable tags is often more useful.
Tests within a suite should be related. Don't have too many tests in a single file, unless they are data driven. Each test should be independent of others and should rely only on setup and teardown. Each test case should test something specific. A large test can possibly cover an end-to-end scenario.
If there are user-defined keywords, document the arguments and return values. Between keywords, assign return values to variables, and then pass these variables as arguments.
-
What are some useful resources and tools for Robot Framework? The official Robot Framework website is a good starting point. Those new to writing tests, can study the examples there. The User Guide is another useful resource.
Beginners should get familiar with some of the standard libraries including Builtin, OperatingSystem, String, Process, DateTime, Collections, Screenshot, and more. The framework has been extended by many third-party libraries. Choose what suits your application. There are libraries to interface or work with Android, Eclipse, databases, Selenium, Django, SSH, FTP, HTTP, MQTT, and more.
Among the useful tools are Rebot for generating logs and reports; Tidy for cleaning or formatting test data files; Libdoc and Testdoc for documentation. Pabot is a tool for parallel execution. Robot Corder can record and playback browser test automation. You can choose among various editors and build tools. There's also a Jupyter kernel.
Milestones
Sample Code
References
- Aro, Ismo. 2018. "Robot Framework Foundation: Welcome to RoboCon." RoboCon 2018, via YouTube, February 15. Accessed 2019-07-30.
- Bristiel, Laurent. 2014. "What editor for Robot Framework test cases." August 17. Accessed 2019-07-30.
- Eficode. 2016. "Robot Framework: Past, Present and Future." Blog, Eficode, June 20. Accessed 2019-07-30.
- Goralight. 2016. "How to handle windows authentication popup in Robot Framework RIDE?" StackOverflow, December 08. Accessed 2019-07-30.
- Jaspers, Thomas. 2012a. "Robot Framework IDE (RIDE) – Overview." Blog, codecentric, January 13. Accessed 2019-07-30.
- Jaspers, Thomas. 2012b. "Robot Framework Tutorial – A complete example." Blog, codecentric, April 27. Accessed 2019-07-30.
- Klärck, Pekka. 2009. "Experience." Eliga Oy. Accessed 2019-07-30.
- Laukkanen, Pekka. 2006. "Data-Driven and Keyword-Driven Test Automation Frameworks." Master’s thesis, Helsinki University of Technology, February 24. Accessed 2019-07-30.
- Nguyen, Thuc. 2019. "Keyword-Driven Testing: The Best Practices You Can’t Afford to Miss." Blog, LogiGear Corporation, February 25. Accessed 2019-07-30.
- QATestLab. 2017. "Guide to Test Automation Tools 2017-2018." Whitepaper, QATestLab. Accessed 2019-07-30.
- Robot Framework Foundation. 2019. "Robot Framework User Guide." Version 3.1.2, May 24. Accessed 2019-07-30.
- RobotFramework. 2019. "Homepage." Accessed 2019-07-30.
- RobotFramework Docs. 2019. "BuiltIn." May 24. Accessed 2019-07-30.
- RobotFramework GitHub. 2015. "Robot Framework 3.0." Release Notes, December 31. Accessed 2019-07-30.
- RobotFramework GitHub. 2019a. "robotframework/robotframework." May 24. Accessed 2019-07-30.
- RobotFramework GitHub. 2019b. "robotframework/RIDE." July 22. Accessed 2019-07-30.
- RobotFramework GitHub. 2019c. "Robot Framework 3.1." Release Notes, April 16. Accessed 2019-07-30.
- RobotFramework GitHub. 2019d. "How to write good test cases using Robot Framework." HowToWriteGoodTestCases, April 05. Accessed 2019-07-30.
- Soukka, Asko. 2018. "RoboCon 2018 and Robot Framework Jupyter support." January 27. Accessed 2019-07-30.
- Wikipedia. 2019. "ISO/IEC 29119." Wikipedia, April 26. Accessed 2019-07-30.
- Yurko, Dmitriy. 2018. "Keyword-Driven Testing with Robot Framework." Blog, Apriorit, September 20. Accessed 2019-07-30.
Further Reading
- Jaspers, Thomas. 2016. "Robot Framework Tutorial 2016." Blog, codecentric, January 08. Accessed 2018-07-31.
- Ihnatsyeu, Dzmitry. 2018. "Robot FrameWork: The Ultimate Guide to Running Your Tests." Blog, BlazeMeter, July 18. Accessed 2018-07-31.
- Robot Framework Foundation. 2019. "Robot Framework User Guide." Version 3.1.2, May 24. Accessed 2019-07-30.
Article Stats
Cite As
See Also
- Acceptance Testing
- Keyword-Driven Testing
- Data-Driven Testing
- Test-Driven Development
- Robotic Process Automation