Robot Framework is a tool used by teams adopting ATDD (Acceptance Test Driven Development).
Broadly speaking, it can be used to automate acceptance “test cases” (i.e. scripts) no matter the moment you decide to do so or the practices your team follows even though it's preferable to do it at start, involving the whole team in order to pursue shared understanding.
In in this tutorial, we will specify some tests using Robot Framework assuming that your team is adopting ATDD.
This tutorial explores the specific integration Xray provides for Robot Framework XML reports.
You may find the full source for this example in this GitHub repository. |
If the team is adopting ATDD and working collaboratively in order to have a shared understanding of what is going to be developed, why and some concrete examples of usage, then the flow would be something similar to the following diagram.
All starts with a user story or some sort of “requirement” that you wish to validate. This is materialized as a Jira issue and identified by the corresponding issue key (e.g. ROB-11).
We can promptly check that it is “UNCOVERED” (i.e. that it has no tests covering it, no matter their type/approach).
A Test Plan can be created to define the scope of the testing that we aim to perform, group, and consolidate the corresponding results. Besides the user story, we may also add the Test Plan to the Board and assign it explicitly to a sprint. This will increase visibility of testing progress and help closing the gap between dev<>testers.
A tester/SDET could simply focus on implementing the automated test cases:
Let’s take the following .robot file as an example, which acts as a suite containing one test case.
*** Settings *** Documentation A test suite with a single test for valid login. ... ... This test has a workflow that is created using keywords in ... the imported resource file. Resource resource.robot *** Test Cases *** Valid Login [Tags] ROB-11 UI Open Browser To Login Page Input Username demo Input Password mode Submit Credentials Welcome Page Should Be Open [Teardown] Close Browser |
The previous Robot file use a common resource that contains some generic variables and some reusable "keywords" (i.e., steps).
*** Settings *** Documentation A resource file with reusable keywords and variables. ... ... The system specific keywords created here form our own ... domain specific language. They utilize keywords provided ... by the imported SeleniumLibrary. Library SeleniumLibrary *** Variables *** ${SERVER} 192.168.56.1:7272 ${BROWSER} Firefox ${DELAY} 0 ${VALID USER} demo ${VALID PASSWORD} mode ${LOGIN URL} http://${SERVER}/ ${WELCOME URL} http://${SERVER}/welcome.html ${ERROR URL} http://${SERVER}/error.html *** Keywords *** Open Browser To Login Page Open Browser ${LOGIN URL} ${BROWSER} Maximize Browser Window Set Selenium Speed ${DELAY} Login Page Should Be Open Login Page Should Be Open Title Should Be Login Page Go To Login Page Go To ${LOGIN URL} Login Page Should Be Open Input Username [Arguments] ${username} Input Text username_field ${username} Input Password [Arguments] ${password} Input Text password_field ${password} Submit Credentials Click Button login_button Welcome Page Should Be Open Location Should Be ${WELCOME URL} Title Should Be Welcome Page |
A Test issue will be auto-provisioned the first time you import the results, based on the name of the test case and of the corresponding test suites.
If you maintain the test case name and the respective test suites, the Test will be reused on subsequent result imports. You may always enforce the results to be reported against an existing Test, if you wish so: just specify its issue key as a tag.
Tags can also be used to cover an existing requirement/user story (e.g. “ROB-11”): when a requirement issue key is given, a link between the test and the requirement is created during the results import process.
Otherwise, tags are mapped as labels on the corresponding Test issue.
Importing results is as easy as submitting them to the REST API with a POST request (e.g. curl), or by using one of the CI plugins available for free (e.g. Xray Jenkins plugin).
In Jira, using Xray, the team can look at the Test Run details which include the overall result and also specifics about each keyword, including duration and status.
We can all see that a Test case/issue was auto-provisioned based on the name of the test case and of the corresponding test suites.
After running the tests and generating the Robot XML report (e.g., output.xml), it can be imported to Xray via the REST API.
If you're using Python:
robot -d output . |
If you're using Java:
java -jar robotframework-3.0.jar -d output . |
Each Robot's test case is mapped to a Generic Test in Jira, having the summary with the name of the test case, and the Generic Test Definition field contains the concatenated names of the test suites along with the name of the test case. Note that Robot Framework considers the base folder of the project as the first test suite. The way you run your tests also affects Robot's XML; so, if you execute the file from somewhere else or you execute the file directly by passing it as an argument, the test suite's information will potentially be different.
You will see information about each Robot keyword (i.e., step) and its corresponding status in the Context section of the Execution Details of the Generic Test.
Right from within the user story issue screen, we now see one test (i.e. automated script) covering it. We can also see its latest result and how it impacts the overall coverage calculation for the user story; if the user story shows as “OK”, you know that all tests covering it passed, accordingly with the latest results obtained for each one of them.
On Agile Boards (e.g. Scrum boards), we can now assess the coverage of our user story taking into account the testing results.
We may also track the overall Test Plan consolidated progress on the Test Plan issue related card. Note that we could include Test Executions in the board if we wish so; however, in CI scenarios that could be counterproductive.
At the Test Plan-level, the entity that defines the scope of testing and tracks its progress, we can quickly assess the latest consolidated test results (i.e. the latest result obtained for each Test being tracked).
Robot Framework
Awesome Robot Framework (curated list of resources)
Code used in this demo
Automation topic in Xray’s documentation
Xray and Robot Framework integration (includes tutorials)
REST API, Jenkins, Bamboo, Team City and integration with other CI tools