Keyword Driven Testing Tutorial: A Comprehensive Guide With Examples and Best Practices

  • Learning Hub
  • Keyword Driven Testing Tutorial: A Comprehensive Guide With Examples and Best Practices

OVERVIEW

Organizations constantly strive to improve, adapt, and become competitive in today's technology-driven world. To keep up with all the changes in the technology industry, organizations need to automate their end-to-end testing processes.

Over the past decade, cutting-edge software testing methodologies have revolutionized the technological industry. The rising demand for Agile and DevOps has transformed traditional testing methods, thereby helping teams to avoid the hassle of slow software release cycles and increasing overall product release velocity.

Keyword driven testing is one of such software testing methodologies that involves describing test cases using a predefined set of keywords. It separates test development from your test design. Basically, Keyword driven testing is a collection of executable keywords that simulate a user's actions, such as logging in, clicking a mouse, typing a name, etc. In Keyword driven testing, you can use the same keywords repeatedly within a single test, which results in more excellent test coverage.

In this Keyword driven testing tutorial, we will look at what Keyword driven testing is, its components, working, and how to perform it.

What is Keyword driven testing?

Keyword driven testing, also known as table-driven testing or action word-based testing, is a type of automated functional testing that separates test case design from test development. It is a collection of keywords that you can reuse within the same tests. In simple terms, a keyword is the combination of a user's action on a test object. Using keywords to describe test steps makes test cases easier to understand, automate and maintain. You can use Keyword driven testing for both manual and automated processes.

In Keyword driven testing, keywords represent user actions such as mouse clicks, keystrokes, object selection, etc. As a result, a keyword driven test can be generated by selecting a predefined keyword that represents a specific action, or simply recording the action, depending on the application.

For example, in the below LambdaTest Login form, the keyword “login” will be used in the automation testing framework to test the login functionality or any action linked to it.

Keyword Driven Testing Process

Keyword driven approach helps in various ways. For example, non-technical folks can understand the test automation process as this approach separates coding from test cases and steps. Also, manual testers can quickly write automation test scripts. A highly skilled coder is required who can regularly set up the test framework and update automation scripts in the background.

A keyword driven framework categorizes test cases into four parts:

  • Test Step − Describes the action performed on the test object.
  • Test Object − Contains the names of web page elements such as usernames, passwords, etc.
  • Action − This refers to a user's action like clicking, an opening browser, etc.
  • Test Data − The value of an object is used to carry out the user’s actions.
Keyword Driven Testing Process

Why perform Keyword driven testing?

Keyword driven testing gives you multiple advantages, such as less maintenance in the long run. You can easily maintain the keywords because all keyword-driven tests using these keywords are automatically updated. Test cases are concise and easier to read and understand for non-technical folks.

Shown below are the reasons why one should run keyword driven tests.

  • There is a standard library for handling the common components.
  • There is a much higher degree of reusability.
  • In writing tests, you can adopt a more abstract approach.
  • Scripting languages are not required for users.
  • Script details are not visible to users.
  • Thus, the test is not only concise but also flexible and easy to maintain.

Benefits of Keyword driven tesing

In this section of the Keyword driven testing tutorial, we will discuss some of the benefits of keyword driven tests.

It is easy to create keyword-driven tests. Test actions can be performed by simply dragging and dropping the keywords that correspond to your desired actions, or you can record their actions, and the keyword-driven test will be built.

Following are a few of the benefits of Keyword driven testing.

  • Enables easy creation of automated UI tests and handles complex scenarios with zero programming knowledge.
  • It has a built-in automation framework that makes it easy to manage automated UI tests and separate test steps, objects, test data, and actions.
  • Convert desktop, mobile, and web keyword tests into scripted tests.
  • Perform automated UI testing more quickly in different testing cycles by reusing keyword-driven tests.
  • In Keyword driven testing, tests are presented in a simplified way. Using an easy-view option, users can see all the operations at once in a spreadsheet or other format.
  • Keyword driven testing extends data Keyword driven testing by allowing its test scripts to read data from data sources like CSV files, ADO objects, and ODBC databases.
  • Functional tests can be run during the early stages of development using Keyword driven testing. As a result, it increases the overall success rate of automated testing and reduces costly setbacks.

How does Keyword driven testing work?

In Keyword driven testing, a sequence of operations is recorded using keywords. Keyword driven tests can be run by dragging and dropping relevant keywords to an action.

In this context, the term "keyword" refers to specific user actions incorporated into test cases by defining specific user actions. A test case specification is based on these keywords. In a keyword test case, keywords are connected with actions in a mutual 1:N relationship. A test automation framework implements each keyword into executable code, which is then used to automate tests. With this framework, keyword test cases are converted into automated test cases.

Keyword Driven Testing Process

In order to abstract individual actions, high-level keywords are used. To describe associated actions, composite keywords are used. Using keywords for test case maintenance and enhancement benefits their modularity. An operation can be modified quickly with a simple change in the keywords.

Phases of Keyword driven testing

The Keyword driven testing process has two phases: the design and development phase and the implementation phase.

  • Design and development phase: Design and development involve a number of actions that explain the keywords to be designed briefly. Each action in this type is associated with a single keyword and is performed sequentially.
  • Implementation phase: In the implementation stage, the final stage of execution may be carried out manually or automatically, depending on the situation. In the primary stage of the function execution, the whole set of commands is executed in a precise order.

Components of Keyword driven testing framework

A Keyword driven testing framework helps separate the test code and the test data to help maintain your test cases resulting in better-automated testing. Further, incorporating the best test automation frameworks like Selenium for writing keyword driven tests makes your test scripts even more reusable and readable, and cuts short maintenance costs.

A A keyword driven framework is made up of various operations and instructions that are specified in an excel file. The instructions or test input data from the excel file are read by the test script. The test input data is then entered into the application under test. The test cases are run, and the results are generated. The test output data (results) are recorded in an excel file.

Keyword Driven Framework

A keyword driven framework requires the following components.

  • Excel sheet − It stores keyword and test data for test cases, test steps, test objects, and test actions.
  • Object repository − It is a text file or property file that collects locator values of web elements. It holds data in the form of key-value pairs.
  • Function library − It is used to perform actions.
  • Test datasheet − It is an excel file that contains data values inside objects to perform actions on them.
  • Test script - Scripts to interact with applications under test using library functions and test data.
  • Selenium (or any other framework) − To configure the test environment.
  • Driver script − Also known as the execution engine. It is used to communicate with test scripts. Driver script collects data from environment variables, reads an excel file, invokes functions mapped with keywords, and displays the results.

Commonly used Keyword driven framework structures

A keyword driven framework's primary objective is to discover some keywords and develop associated functions. You can implement the Keyword driven testing approach in a variety of ways. The framework can be broadly classified into two types based on keywords.

  • Frameworks in which keywords are mapped with entire functions: The functions, in this case, are a collection of various actions or steps. For example, the login function is a set of steps. When a keyword is mapped with a function, it implies that a single keyword is associated with a set of steps.
  • Keywords are mapped with the lowest level action on an object in frameworks: The function you perform on an object is the lowest level operation. For example, if you want to perform a click operation on a button or a set or type operation on a text box, the keywords you'll use in this case are set, click, and type.

    These keywords will be associated with functions that simply click on an item or enter a value into a text box. In other words, the function mapped with this keyword will only perform one action.

Let’s look at the below sample test cases for the above keyword driven framework structures to understand them more effectively.

  • TC_01: Log in to Gmail, count the number of emails you sent today, and then sign out.
  • TC_02: Log in to Gmail, then send an email to one of your recipients and then sign out.
  • TC_03: Log in to Gmail, count the number of emails you received today, and then sign out.

Differences: Data driven and Keyword driven testing

This section of this Keyword driven testing tutorial focuses on the differences between data-driven and Keyword driven testing.

When automating tests, you can use various data inputs to achieve a wider test range. With data-driven testing, you run your test with a varied set of input data to ensure that the application will work as expected if the variable values are changed. This technique involves using data as inputs for script actions. In the script, each data set represents a test case. Therefore, the more data sets you provide, the more test cases you have.

On the other hand, Keyword-driven testing allows you to define actions based on keywords. In a script, keywords are used to drive the action. Using the same keywords, you can create a variety of test scripts.

Let’s look at how data-driven testing is different from Keyword driven testing.

Data driven testingKeyword driven testing
It involves testing using different stored data, values, and variables. It involves testing using specific keywords.
Store data in various formats like CSV files, excel sheets, databases, tables, etc.Store data in excel sheets.
The user decodes all test scripts.The user encodes all test scripts.
It can occur in several stages.It can occur in two different stages.
This method is less time-consuming.This method is more time-consuming.
It is a time-consuming process.It is the least time-consuming method.
It requires coding and technical expertise to run tests.No coding or technical expertise is required.
It doesn’t require extensive planning. It requires extensive planning.

Limitations of Keyword driven testing

Keyword driven testing has some of its own limitations. These are as follows -

  • The creation and management of keywords for varying types of actions can be challenging for large projects and is susceptible to scalability issues.
  • It has a moderately high learning curve at the beginning.
  • Without an appropriate planning phase, a keyword-driven framework may create redundant keywords. To make the framework productive and efficient, it's essential to create meaningful keywords.
  • A highly skilled coding and technical folks are required to implement the functions mapped to keywords.

Tools for Keyword driven testing

Following are some of the tools used to perform Keyword driven testing.

  • Selenium: Selenium is the most popular and widely used web testing solution today. It supports a variety of operating systems, including Windows, Mac, and Linux, as well as popular browsers, such as Firefox, Chrome, IE, and Headless browsers. Using the Selenium framework, code maintenance is easy and efficient.

    In Selenium, a keyword driven framework is a mechanism for speeding up automated testing by separating keywords for a common set of functions and commands. All actions and instructions are written in an external file, such as an Excel sheet. Users have complete control over and specify the capabilities they want to test.

  • Ranorex: Ranorex is a commercial keyword-driven test automation platform. It makes it possible for individuals with a basic understanding of programming to build reusable automation modules and combine them to create keyword-driven test cases. With Ranorex, test engineers can write test cases without a single line of code.

    Ranorex Studio's powerful object recognition, capture, and replay features enable you to build sophisticated tests. By using the tool, you can capture user actions and then add validations to them. Furthermore, you can combine keywords with data-driven testing, global parameters, and conditional execution.

  • Robot: Robot Framework is another powerful keyword-driven test automation framework. Robot Framework is a generic test automation framework that is very useful for automating acceptance testing. Robot Framework is primarily written in Python. Automated tests can be readable and easier to create when used for Keyword driven testing. The Robot framework integrates well with Selenium WebDriver, popular APIs, Appium, and MongoDB.

How to perform Keyword driven testing?

You can perform both manually and automated Keyword driven testing However, it is typically used with automated testing.

Automating your keyword driven tests help in,

  • Lowering maintenance costs.
  • Avoiding redundant specifications.
  • Increasing reusability of function scripting.
  • Improving test support and portability.
  • Performing extensive testing.

You can write simple, functional tests with Keyword driven testing in the early phases of development. The most simple way to create keyword-driven tests is to record them and modify and customize them after the tests have been recorded. You need to link each keyword to at least one command, test script, or function that performs the activities involved with that keyword. When test cases are run, keywords are parsed by a test library, which is invoked by a test automation framework like Selenium.

When running keyword driven tests, testers can choose cloud-based automated browser testing platforms like LambdaTest. It lets you perform Keyword driven testing on blazing fast online Selenium Grid and exponentially increase your browser coverage by running your Selenium test scripts on a test automation cloud of 3000+ different desktop and mobile environments.

LambdaTest also offers several other test automation frameworks like Cypress, Playwright, and Puppeteer for automated cross browser testing.

Subscribe to the LambdaTest YouTube Channel and get the latest tutorials around Selenium testing, Cypress E2E testing, Responsive testing, and more.

When it comes to mobile test automation, you can automate your mobile application testing with the best app testing frameworks like Appium, Espresso, and XCUITest.

Wrapping up!

Keyword-driven testing requires a lot of planning, which can be time-consuming and resource-intensive. However, once the keyword-driven framework is set up, the rest of the testing process is much easier.

You can use automated testing frameworks like Selenium to set up your keyword-driven testing framework, even if you do not have any technical knowledge.

Frequently Asked Questions (FAQs)

What is Keyword driven testing in Selenium?

Using a Keyword driven testing framework, all operations and instructions are written in an external excel file. Test automation frameworks like Selenium help separate the code and the data to help maintain test cases. This makes it easier to read, reuse, and reduce the cost of maintenance.

Why do we perform Keyword driven testing?

Keyword driven testing gives you several advantages, such as reduced maintenance in the long run. Test cases are concise and easier to read and understand for non-technical folks.