Keyword-driven testing is rather new, yet itโs already one of the most widely used approaches for application testing. While itโs suitable for manual testing, this approach is mostly used for automated testing.
In this article, we describe the basics of keyword-driven testing, highlight its main pros and cons, and explain how to run keyword-driven tests with the help of Robot Framework.
Contents
The keyword-driven testing approach
The keyword-driven testing (KDT) approach uses keywords (action words) to determine the functionality under test. Basically, these action words simulate real user actions on the tested application.
KDT separates high-level documentation of test cases from low-level keyword documentation that contains the details of test case execution. This approach is often referred to as table-driven testing or action word-based testing.
This approach consists of two main layers:
- Infrastructure layer โ This layer is used as the engine that receives keywords and runs operations on the tested application. The infrastructure layer includes such elements as utility functions, item operations, and user-defined functions.
- Logical layer โ This layer is based on test cases and is used for building and executing test scripts with the help of predefined keywords.
Letโs take a look at some basic types of keywords. In the case of KDT, keywords serve as blocks for building test cases. There are three main types of keywords:
- Item Operation (Item) โ A keyword that determines an action that performs a specific operation on a given component of the applicationโs graphical user interface (GUI).
- Sequence โ A set of action words determining a functional process, such as Create User. Sentences are widely used for implementing frequently used functional processes.
- Utility Function (Function) โ A keyword that symbolizes a script executing a certain functional operation that canโt be implemented as a sequence.
A test case is a table containing keywords and test data, or arguments (see Figure 1).
As you can see from the table above, all keywords are listed sequentially, each starting on a new line. These keywords determine the progress of the test case.
A keyword can be complex, consisting of several action words, or it can be implemented in a specific programming language. For instance, Figure 2 below shows what the keyword Create User might look like:
In this example, the Create User keyword consists of a set of other action words, the implementation of which can be stored in a separate library.
One of the main benefits of using KDT is that it makes it more practical to support tests: high-level test cases can remain constant while low-level details of keyword implementation can be changed if needed. Plus, KDT allows automation engineers to plan test automation at the software development stage, even before the application is ready.
However, this approach has both pros and cons. In the next section, we take a look at the main advantages and disadvantages of KDT for performing a particular kind of tests โ automated acceptance tests.
Pros and cons of keyword-driven acceptance testing
Acceptance testing is one of the most important parts of the software testing process. A keyword-driven testing framework can be used to automate this stage and make it more efficient. Robot Framework is commonly used for acceptance testing, and weโll get back to it shortly. But for now, letโs look closer at the main pros and cons of KDT for automated acceptance testing.
Pros:
- Test cases are easy to read as there are no implementation details.
- Supporting test cases doesnโt require additional expenses.
- Keywords can be reused in different test cases.
- Development of test cases and keywords can be distributed within the team.
- Thereโs no binding to a particular programming language.
Cons:
- Developing initial keywords can take a long time.
- Keywords need to be modified when changing the environment or implementation.
- Learning a new framework or programming language requires additional time.
Using Robot Framework for automated acceptance testing
The main purpose of Robot Framework is test automation. In particular, this framework is widely used for acceptance testing. Itโs an open source project, so you can find all information about the framework and how to use it, including Robot Framework data-driven test examples, on the projectโs official website.
With Robot Test Framework, you can develop tests in Python, Java, and .NET. The syntax for describing test cases is based on a KDT approach and a table format.
To install and start working with this framework, youโll need a Python interpreter and the pip package manager. To install the framework, use the following command:
pip install robotframework
Robot Framework has several key features:
- Simple tabular test format
- Universal keyword libraries
- The ability to create custom libraries in Python, Java, and .NET
- Detailed HTML reports and logs
- Continuous integration plugins
Itโs also possible to integrate Robot Framework with an integrated development environment (IDE) such as PyCharm. After installing an appropriate plug-in (for example, robot-plugin or IntelliBot), the syntax of the framework is highlighted and tests can be run directly from the IDE.
In addition to keyword-driven tests, Robot Framework can be used to create data-driven and behavior-driven (Gherkin) tests.
Now letโs see how to compose an automated acceptance test with the help of Robot Framework.
Composing tests
In Robot Framework, tests are sets of tables that contain test data, variables, keywords, and advanced settings (such as library imports and metadata). Each table begins with its name. There are four possible names for Robot Framework tables:
- Settings
- Variables
- Test Cases
- Keywords
Robot Framework supports several file formats for test cases. The preferred formats are HTML, TSV (tab-separated values), space-separated, and reST (reStructuredText).
Letโs take a closer look at the test case syntax in the following example. Suppose the test object is designed to monitor file operations in Windows and consists of a driver and a service. The following test shows how to install the application and verify that the service is logging all file operations.
Driver_test.robot:
*** Settings ***
Resourceย ย ย Agent_resources.robot
Libraryย ย ย ย OperatingSystem
*** Variables ***
${msi}ย ย ย ย ย ย ย ย C:InstallationsAgent.msi
${log_file}ย ย ย C:Program DataAgentService.log
${driver}ย ย ย ย ย fs_driver
${service}ย ย ย ย fs_service
*** Test Cases ***
Driver installation
ย ย ย [Tags]ย ย ย Installation
ย ย ย Install The Driverย ย ย ${msi}
ย ย ย Service Should Be Startedย ย ย ${service}
ย ย ย Driver Should Be Loadedย ย ย ${driver}
File system logging
ย ย ย [Tag]ย ย ย Service
ย ย ย [Setup]ย ย ย Enable File System Logging
ย ย ย Generate Read File Operations
ย ย ย Generate Write File Operations
ย ย ย Service Log File Should Contain FS Operations
ย ย ย [Teardown]ย ย ย Disable File System Logging
*** Keywords ***
Install The Driver
ย ย ย [Arguments]ย ย ย ${msi}
ย ย ย ${install_result}= install_agentย ย ย ${msi}
ย ย ย Should Be Equal As Integersย ย ย ${install_result}ย ย ย 0
Service Should Be Started
ย ย ย [Arguments]ย ย ย ${service}
ย ย ย ${result}=ย is_service_runningย ย ย ${service}
ย ย ย Should Be Trueย ย ย ${result}
This is an example of a space-separated test format where each value (keyword, table, variable) is separated by at least two spaces.
First, we define the settings table. In our case, we use this table to import a standard OperatingSystem keywords library from the framework. In addition to standard libraries, you can import custom libraries that have been specially created for a particular application. In this example, we use the custom Agent_resources.robot library.
Next, we move to defining the variables table, which lists the required variables. In test cases and keywords, variables are used to store temporary information. In our case, we use such variables as the installation path, log file, and names of the driver and the service.
Then we move to the test cases table, which describes high-level test cases. Each test case begins with a title. In our case, we have two test cases: Driver installation and File system logging.
Cases consist of a set of keywords and are described in a user-friendly language, without any low-level implementation details. You can add a specific tag to a test case in order to filter the statistics once the testing is finished. You can also specify the setup/teardown procedures needed for bringing the system to a certain initial state and returning to that state after finishing the test.
Finally, we define the keywords table, which contains details of keyword implementation. Each keyword can consist of other keywords created in the Robot Framework format and can be implemented as a function in a separate Python or Java library.
Running tests: launching and reports
Now, letโs take a look at the process of launching tests and getting their results in Robot Framework. A test is launched from the command line with a simple command:
robot Driver_test.robot
Test results can be displayed on the command line and in an HTML report:
This report shows you the statistics for particular tests or a set of tests marked with a common tag.
However, filtering isnโt the only use for tags. You can also use them for including or excluding particular test cases from being executed:
robot --include Installation --exclude Negative Driver_test.robot
Tags can also be used for determining the level of importance of a particular test:
robot --critical Web Driver_test.robot
Since Robot Framework is both system- and platform-independent, you can test your application on Windows, Mac, Linux, or Unix. To increase your chances of finding possible bugs and issues in your application, you can configure the framework to run all tests randomly.
Conclusion
Robot Framework is a universal framework for automated acceptance testing based on a keyword-driven approach. The main benefit of this approach is that it allows you to compile high-level test cases in a user-friendly language.
The framework contains a wide range of keyword libraries. Plus, you can always access detailed test reports and useful tools for working with the framework on the official Robot Framework website.
At Apriorit, we have a team of dedicated quality assurance professionals. Use the form below to contact us. We would be glad to assist you in building efficient test processes to meet any needs, from mobile app testing to driver quality assurance.