Keyword Driven Framework for Selenium

On This Page What is Keyword Driven Framework?April 03, 2026 · 11 min read · Tool Comparison

Keyword Driven Framework for Selenium

A Keyword Driven Framework for Selenium allows testers to separate test case logic from the code, making it easy to automate and sustain tests.

Overview

Keyword Driven Framework allows testers to compose test using a set of predefined keywords, enable them to express test cases in a natural language format. This model enhances reusability, scalability, and readability, making it ideal for large-scale testing projects.

Components of Keyword Driven Framework:

  • Keywords: Predefined actions (e.g., click, type, verify) used to symbolize test steps.
  • Test Data:External information sources (e.g., Excel, CSV files) containing inputs for exam cases.
  • Test Scripts:Automation scripts that use keywords to execute the literal test stairs.
  • Keyword Repository:A centralised fix that stores all the predefined keywords and their associated actions.
  • Driver Script:The principal playscript that say keywords from tryout data and triggers the execution of equate actions in Selenium.

The article explores the conception, benefits, factor, and implementation of a Keyword Driven Framework in Selenium, along with its conflict from Data Driven Framework.

What is Keyword Driven Framework?

The keyword-driven framework is based on keywords that form the basis of the functionality, direct in parameters, and throw the relevant output. When the code has to continue a lot of functionality, it might need repetitive composition for some section. Thus, keywords are written to pinch the complexity of the code.

  • The operation or methods are written severally from the script as keywords.
  • These keywords, rate in an external file (Excel sheet), are called utilize the code. This enables testers to keep each of the functionalities separate.
  • The steps of each test suit are represented using keywords, and each keyword is assort with relevant parameter.
  • Testers can create and alter test cases without dealing with the underlying mechanisation code, making the operation more user-friendly.

Read More:

What is a Keyword Driven Framework in Selenium?

A Keyword Driven Framework in Selenium is an automation framework where test cases are created employ a set of predefined keywords, representing action like & # 8220; pawl, & # 8221; & # 8220; enter text, & # 8221; or & # 8220; verify. & # 8221;

These keywords are map to corresponding Selenium commands, allowing tester to design tests in a more readable and perceivable format. This approach separates the test logic from the code, making test conception and maintenance more efficient.

Here ’ s a process flow to understand how it works.

  1. The mechanization script will read the instructions or test stimulation data from the Excel sheet
  2. The stimulation data is recruit in the application under exam
  3. The test cases are performed and results are returned
  4. The tryout yield datum is stored in the Excel sheet

What is Keyword Driven Testing?

Keyword-Driven Testing, or Keyword-Driven Testing Framework or simply Keyword Testing is a test mechanization framework that abstracts the technical details of test implementation and allow testers to make and cope test using a more user-friendly and business-oriented language.

Tests are correspond using a sequence of keywords, where each keyword equate to a specific activity or operation to be performed on the covering under test. These keywords are delineate in a library or repository, and examiner use them to create test cases by combining keywords in a meaningful sequence.

Read More:

Why perform Keyword Driven Testing?

Keyword driven prove addresses common challenges in test automation by providing a structured approach that separates test design from automation implementation. The following are the benefit:

  • It empowers technical and non-technical stakeholder to collaborate effectively, ensures efficient test case maintenance, and enhance the overall quality of the testing operation.
  • With Keyword-Driven Testing, modifying or updating tests often involves changing the keyword definition or argument rather than rewrite entire test script.
  • Test cases can be developed more apace using predefined keywords, as they encapsulate complex mechanization logic.
  • High-level keywords make conveying try progression and solvent easier for management and early team.
  • Using standardized keywords promotes consistency in test lawsuit design and execution.
  • Test cases can be easy customise by rearrange, adding, or modify keywords to create new testing scenario.

Tools Used for Keyword Driven Testing

  • Selenium with TestNG or JUnit: Selenium can be combined with essay frameworks like or to create a Keyword-Driven Testing framework. You can delineate keywords as methods and use annotations or contour file to map keywords to actual test activity.
  • Robot Framework: is a powerful and user-friendly test automation model that supports Keyword-Driven and Data-Driven Testing. It has built-in keywords for various activity; you can make custom keywords. It has a elementary tabular syntax for tryout case design and supports various test libraries and extensions.

To further raise your Keyword-Driven Testing procedure, consider using BrowserStack Automate. It allows seamless cross-browser testing on real device and browser, ensuring that your keyword-driven tests act cleanly across various environments. Automate your Selenium handwriting with BrowserStack to achieve fast test executing, greater reliability, and comprehensive test reporting.

Advantages And Disadvantages of Keyword Driven Testing Framework

The next outlines the advantages and disadvantages of using a Keyword Driven Testing Framework, providing perceptiveness into its forcefulness and potential restriction.

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

AdvantagesDisadvantages
Code ReusabilityKeyword Management
Platform sovereign Test ScriptsExtensive Planning
Enhanced ProductivityExpertise demand to pen test scripts
Application abstractionTime taken to write test handwriting is high than common

The benefits are evident enough to evidence the mettle of Keyword Driven Framework in Selenium. Testers can overcome many challenges while habituate other fabric approaches utilise Keyword Driven Framework in Selenium.

Components of a Keyword Driven Framework

The components of a Keyword Driven Framework include essential elements that work together to enable efficient and structured test mechanisation.

  1. Excel Sheet& # 8211; It is used to store the data for examination case, such as keywords
  2. Object Repository& # 8211; This stores the locator values for web elements
  3. Function Library& # 8211; It is used to create functions that perform activeness
  4. Test Data Sheet& # 8211; This is an Excel file storing the data value within objects
  5. Test Scripts& # 8211; These are the book to interact with the covering under exam
  6. Driver Script& # 8211; This is the driver engine that interacts with all test scripts
  7. Selenium& # 8211; It is used for environment setup. Other tools can also be used for this purpose

Read More:

Keyword Driven Framework Using Selenium WebDriver

Here is a simple plan of a keyword-driven framework using a scenario that automates the end-to-end flowing of a web application.

Frameworks in help tell the codification and the information to help maintain test cases. Frameworks supporter make the code reusable, readable, and reduce the toll of maintenance. This section will explore a Keyword Driven Testing Framework use.

Let ’ s create a simple design of a keyword-driven framework with the helper of a scenario. The scenario will automate the end-to-end flow of a web application.

Scenarios to be automatise:

  1. Open a Browser
  2. Navigate to URLhttps: //bstackdemo.com/
  3. Click the Sign In button
  4. Enter Username
  5. Enter password
  6. Click on the Login button
  7. Validate username on homePage
  8. Click on the Logout button
  9. Close the browser

Prerequisites:

  1. First
  2. and add habituation in the pom.xml file below, which contains dependencies related to the Selenium project and excelSheethandling.
& lt;? xml version= '' 1.0 '' encoding= '' UTF-8 ''? & gt; & lt; labor xmlns= '' http: //maven.apache.org/POM/4.0.0 '' xmlns: xsi= '' http: //www.w3.org/2001/XMLSchema-instance '' xsi: schemaLocation= '' http: //maven.apache.org/POM/4.0.0 http: //maven.apache.org/xsd/maven-4.0.0.xsd '' & gt; & lt; modelVersion & gt; 4.0.0 & lt; /modelVersion & gt; & lt; groupId & gt; com.keyword_driven_framework & lt; /groupId & gt; & lt; artifactId & gt; keyword_driven_framework & lt; /artifactId & gt; & lt; version & gt; 1.0-SNAPSHOT & lt; /version & gt; & lt; property & gt; & lt; maven.compiler.source & gt; 1.8 & lt; /maven.compiler.source & gt; & lt; maven.compiler.target & gt; 1.8 & lt; /maven.compiler.target & gt; & lt; /properties & gt; & lt; dependencies & gt; & lt;! -- Other dependencies, if any -- & gt; & lt;! -- Selenium WebDriver -- & gt; & lt; colony & gt; & lt; groupId & gt; org.seleniumhq.selenium & lt; /groupId & gt; & lt; artifactId & gt; selenium-java & lt; /artifactId & gt; & lt; version & gt; 4.0.0 & lt; /version & gt; & lt;! -- Replace with the late variant available -- & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; io.github.bonigarcia & lt; /groupId & gt; & lt; artifactId & gt; webdrivermanager & lt; /artifactId & gt; & lt; version & gt; 5.3.1 & lt; /version & gt; & lt;! -- Use the latest version usable -- & gt; & lt; /dependency & gt; & lt; dependency & gt; & lt; groupId & gt; org.apache.poi & lt; /groupId & gt; & lt; artifactId & gt; poi-ooxml & lt; /artifactId & gt; & lt; version & gt; 3.11 & lt; /version & gt; & lt; /dependency & gt; & lt; /dependencies & gt; & lt; /project & gt;

Step 1: To design a Keyword Driven Framework, first identify all the actions to be performed for automated examination of an application. In the above scenario, seven step feature to be completed.

Step 2: Once all actions are identified, the next stride is to create a keyword map table in the Excel sheet. Keyword map table is a table in an Excel sheet that defines all the keywords available for examination automation projects.

The table below present the keyword map table for the above scenario

Step 3: Once all keywords have been identified, the next step is to place the Excel sheet in the task package. Create a packet named ‘ excelData ’ by right-clicking on the Project. For this, go to New & gt; Package.

Place the newly created Excel file in the bundle directory locally on the computer. The package structure of the keyword-driven framework can be seen in the screenshot below.

This structure is highly urge as it is easygoing to understand, use, and maintain.

Read More:

Step 4: Create a new package identify “utility”. Now, create a new class file named “Constants” in which the tester will define constant likeURL, filePath, and excelData. Source codification look as below:

package com.keyword_driven_framework.utility; public class Constants {public static final String URL = `` https: //bstackdemo.com/ ''; //Mention the route to your excel file public static final String filePath = `` D: \\DemoFile.xlsx ''; public static final String excelData = `` DemoFile.xlsx ''; public static final String username = `` Your_Username ''; public static concluding String watchword = `` Your_password '';}

Step 5:Now, write code for each action keyword. Create a new package named “keywordDriven”. Create a new class file named “Action_Keyword”. In this class, create methods for each Action Keyword identified in Excel.

package com.keyword_driven_framework.keywordDriven; import java.time.Duration; import org.openqa.selenium.By; importation org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import com.keyword_driven_framework.utility.Constants; public class Action_keyword {public static WebDriver driver; public void openBrowser () {System.setProperty (`` webdriver.gecko.driver '', '' path_to_driver ''); FirefoxOptions options = new FirefoxOptions (); WebDriver driver = new FirefoxDriver (options); driver.manage () .window () .maximize ();} public void navigate () {driver.manage () .timeouts () .implicitlyWait (Duration.ofSeconds (10)); driver.get (Constants.URL);} public void clickSignIn_h () {driver.findElement (By.xpath (`` //a [@ id='signin '] '')) .click ();} public void enterEmail () {driver.findElement (By.xpath (`` (//div [@ class= ' css-1wa3eu0-placeholder ']) [1] '')) .sendKeys (Constants.username);} public nihility enterPassword () {driver.findElement (By.xpath (`` (//div [@ class= ' css-1wa3eu0-placeholder ']) [2] '')) .sendKeys (Constants.password);} public null clickSignIn () {driver.findElement (By.xpath (`` //button [@ id='login-btn '] '')) .click ();} public null verifyUserName () {String username =new String (`` your_username ''); username.equals (driver.findElement (By.xpath (`` //span [@ class='username '] '')));} public void logout () {driver.findElement (By.xpath (`` //a [@ id='logout '] '')) .click ();} public void verifySignBtn () {String signIn =new String (`` Sign In ''); signIn.equals (driver.findElement (By.xpath (`` //a [@ id='signin '] '')));} public void closeBrowser () {driver.quit ();}}

Step 6:Write codification to say data from an Excel sheet in this step. For this, use an Apache POI library, which let tester to say, create, and edit Microsoft Office documents using Java.

Create a new package named “excelUtility” and then create a new class file named “ReadExcelSheet”. Look at the following source code to read all keywords from the step table.

package com.keyword_driven_framework.excelUtility; import java.io.File; import java.io.FileInputStream; meaning java.io.IOException; import java.util.ArrayList; importation java.util.Iterator; significance org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; importee org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; importation com.keyword_driven_framework.utility.Constants; public class ReadExcelSheet {public ArrayList readExcelData (int colNo) throws IOException {String filePath = Constants.filePath; File file = new File (filePath); // Create an object of FileInputStream class and pass file as argument to its builder. FileInputStream fis = new FileInputStream (file); XSSFWorkbook wb = new XSSFWorkbook (fis); XSSFSheet sheet = wb.getSheet (`` Sheet1 ''); Iterator row = sheet.rowIterator (); row.next (); ArrayList & lt; String & gt; a = new ArrayList (); // Checking the future element availableness using the reference varying row. while (row.hasNext ()) {Row r = (Row) row.next (); // Moving cursor to the cell by acquire a cell number. Cell c = r.getCell (colNo); String data = c.getStringCellValue (); a.add (data); a.add (((Row) row.next ()) .getCell (colNo) .getStringCellValue ());} System.out.println (`` List: `` +a); // Return the datum to the Arraylist method. regress a;} public void DemoFile (int i) {// TODO Auto-generated method nub}}

Step 7: Next footstep is to write code for callingreadExcelData () method of ReadExcelSheetclass and methods ofActionKeywordsclass. Create a new package name “executionEngine” and write the following rootage code by create a category nominate “ExecutionTest”.

package com.keyword_driven_framework.executionEngine; signification java.io.IOException; import java.lang.reflect.InvocationTargetException; import com.keyword_driven_framework.excelUtility.ReadExcelSheet; import com.keyword_driven_framework.keywordDriven.Action_keyword; public class ExecutionTest {public inactive void main (String [] args) throws IOException, Exception, IllegalArgumentException, InvocationTargetException {ReadExcelSheet rs = new ReadExcelSheet (); rs.DemoFile (4); Action_keyword k = new Action_keyword (); k.openBrowser (); k.navigate (); k.clickSignIn_h (); k.enterEmail (); k.enterPassword (); k.clickSignIn (); k.verifyUserName (); k.logout (); k.verifySignBtn (); k.closeBrowser (); System.out.println (`` Test executed successfully '');}}

Observe the output by fulfil the code:

A more advanced keyword-driven fabric would involve data-driven capabilities, better error treatment, and more modular test scenarios and keyword organization.

Talk to an Expert

Difference Between Data Driven And Keyword Driven Framework

Keyword Driven FrameworkData Driven Framework
Easy to maintain due to more generalisation layers between trial scripts, test data, keywords, etc.Comparatively harder to conserve since the generalisation is only between tryout data and test scripts
Planning has to be extensive and precise for keyword driven fabricPlanning is easy since it is only needed for tryout information and test scripts
It is possible to write test scripts even before the production has finished development stageOne has to look for development to finish before writing test cases

Overall, we can reason that Keyword-Driven Testing aims to improve the efficiency and effectivity of software screen by providing a integrated, reclaimable, and maintainable approach to screen automation.

Conclusion

A Keyword Driven Framework for Selenium offers a structured and effective approach to test automation by separating tryout logic from codification. It raise readability, reusability, and scalability, making it suitable for both technical and non-technical teams.

While it comes with its own set of challenge, such as maintaining a orotund set of keywords, its benefits in improving quislingism and simplifying test creation make it a knock-down tool for automating web application testing.

Tags
65,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free