Keyword-Driven Testing (KDT) is a software testing approach that uses a table or a spreadsheet to know which actions should be performed during testing. You would typically use descriptive keywords when creating test cases, which then correspond with an action.
This type of testing is easier to understand for non-technical users, such as QA people or business/marketing colleagues, as it does not require the knowledge of computer programming.
Implementing Keyword-Driven Testing with Selenium
Selenium is a widely used open-source framework for automating web browsers. In the example below, we'll show you how you can start using Keyword-Driven Testing with Selenium.
Define keywords
First, let's come up with a set of keywords that represent actions or operations you want to perform on your website. This could be keywords such as openBrowser
, navigateTo
, click
, verifyText
, etc. If you're familiar with Selenium IDE, this looks a lot like the syntax Selenium IDE uses.
Create Keyword Test Cases
You can now develop test cases using these keywords in a tabular format. Each row in the table represents a test step, with columns specifying the keyword, the target element and any optional parameters.
| Keyword | Target Element | Parameters |
|--------------|---------------------|---------------------|
| openBrowser | chrome | |
| navigateTo | https://testingbot.com | |
| click | loginButton | |
| verifyText | welcomeMessage | Welcome, User! |
Implement Keyword Functions
Create functions or methods that correspond to each keyword. These functions encapsulate the Selenium WebDriver API calls which required to execute the specified action on the (remote) browser.
public void click(String targetElement) {
driver.findElement(By.id(targetElement)).click();
}
public void verifyText(String targetElement, String expectedText) {
String actualText = driver.findElement(By.id(targetElement)).getText();
Assert.assertEquals(actualText, expectedText);
}
Now you can execute the test with a test runner that is capable of reading and interpreting the table. A popular test framework that allows you to do this is Robot Framework.
Advantages of Keyword-Driven Testing
There are several advantages in using Keyword driven testing.
-
Abstraction of Technical Details
Non-technical team members can contribute to test case creation without knowledge of programming or test automation frameworks.
-
Improved Maintainability
Changes in the application's UI or functionality can be accommodated with minimal impact on test cases, simply by updating the keyword functions.
-
Reusable Test Components
Keyword functions can be reused across multiple test cases. This greatly improves the efficiency during test script development and maintenance.
-
Enhanced Collaboration
Collaboration between technical and non-technical team members is improve. This in turn leads to a more inclusive testing process.
What are the differences between Data Driven And Keyword Driven Frameworks?
Data-Driven Testing (DDT) and Keyword-Driven Testing (KDT) are both popular frameworks in test automation. They do however serve different purposes and emphasise on different aspects of testing. Below are some of the differences between these two types of frameworks.
Data-Driven Testing (DDT) | Keyword-Driven Testing (KDT) |
---|---|
The primary focus of Data-Driven Testing is to separate test data from test scripts. It allows testers to execute the same test script with different sets of input data. This is particularly useful for validating different scenarios and variations of the same functionality. | Keyword-Driven Testing aims to abstract the test script's technical details and make the testing process more accessible to non-technical stakeholders. It involves creating tests using descriptive keywords, where each keyword corresponds to a specific action. |
In DDT, test data is typically stored in external data sources like Excel sheets, CSV files or databases. The test script reads input data from these sources during test execution. | While data can be utilized in Keyword-Driven Testing, the emphasis is on using keywords to describe actions, rather than managing extensive sets of input data. The handling of data is not the primary focus. |
Test scripts in DDT are designed to be generic and reusable. They are often parameterised to accept input data. The same script can be executed with multiple data sets. | Test scripts in KDT are structured around keywords, where each keyword represents a specific action. Test cases are constructed using these keywords. This makes the test script more readable. |
DDT is generally more focused on technical aspects and might require programming skills to manage and manipulate test data effectively. | KDT is designed to involve non-technical stakeholders, such as business analysts or domain experts, in the testing process. Test cases are constructed using descriptive keywords, which makes it easier for non-programmers to help when creating and maintaining tests. |