Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Selenium Framework 5: Understand Keyword Driven Framework in Selenium

Posted on 03/21/2025 By admin

A “Keyword” is a wrapper of an atomic action or a chain of actions to achieve a task. These keywords are reusable and building blocks of writing a flow. It shows abstraction concept of OOPS. It is callable. Mostly “Keyword” will be a method.

Let’s understand it considering a real time scenario:-

You need to write automation script for below test case:-

  1. Launch any browser.
  2. Load Google URL.
  3. Type “Selenium” in search box.
  4. Hit “Enter” button.
  5. Click on first link of search result.
  6. Get the URL.
  7. Save this URL in to any external file.
  8. Close the browser.

Let’s apply keyword driven strategies on it.

Create a single keyword or method to perform all above steps. To make a keyword reusable , we must identify its driving factors. For example:- User may ask to launch any browser. So my keyword must provide that flexibility to user. We could create specific keyword for each browser like launchChrome, launchFirefox which will not be a good design. We can create a common keyword to launch a browser by parameterizing keyword.

I will identify driving factors of keyword which will act as parameters to it.

Driving factors:-

  1. Browser to be launched.
  2. Search literal to enter in Google search box.
  3. External file to store data.

searchStoreURL( String browserName , String searchLiteral, File fileToSaveData)

You can use above keyword for different search literals, browsers and files to save. It is reusable. It exhibits abstraction concept of OOPS. Whoever wants to perform similar tasks, they will call this keyword without bothering how it is done which is called abstraction in OOPS.

In above strategy, you mixed up every steps. You have written logic to launch browsers, entering URL, typing literals, click, extracting URL, writing in to a file and closing browsers all in once. If someone just want to load a URL or writing in to a file, they can not use above keyword. We should conclude now that a keyword is a lower level functions. Let’s break above scenario in number of lower level keywords:-

  1. Launch a browser :- launchBrowser(String browserName)
  2. Load a URL:- loadURL(String url)
  3. Verify title to ensure correct URL loaded: verifyTitle(String expectedTitle)
  4. Type a text : enterText(String textToType)
  5. Click:- performClick()
  6. Extract URL or get current url : getCurrentlyLoadedURL()
  7. Writing in to a file: – writeToFile(String fileName)
  8. Closing browser:- closeBrowser()

Let’s create some keywords which perform multiple actions together:-

  1. loadURLAndAssertTile(String url, String expectedTitle) :- Combination of loadURL(String url) and verifyTitle(String expectedTitle) .
  2. clickOnFirstResult()

All above keywords represent lower level functionality to perform atomic task or a chain of tasks. These can be reused for many other scenarios. These are actually reusable to a great extent.

Let’s think more on these keywords and divide them into two categories:-

  1. Keywords which are not specific to application.
  2. Keywords which are specific to application.

[table id=9 /]

All general keywords listed above can be used for any other scenario, applications where similar technology is used. General keywords can be categorised as Selenium Framework (If using selenium) while application specific keywords can be categorized as application specific framework.

Above is called a Keyword driven approach. Now it’s up to you how you utilise these keywords. You can use directly call it in scripts or through external sources like excel, json, database etc.

You mainly need to focus on keywords to make it more custom, parameterized, reusable, scalable and manageable, powerful. You should add validation. logging, reporting stuff , Exception handling in keywords. Powerful keywords will reduce number of lines in test scripts.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappySelenium

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 53: DataProvider in TestNG – Is It Mandatory To Have Return Type as Object in DataProvider Method
Next Post: REST Assured Tutorial 72 – How To Compare Part of JSON Objects and Arrays using JSONassert library

Related Posts

Selenium Topics – Page 14 – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
Postman Tutorial Part 4 – Sending GET Request With Query Params in Postman Uncategorized
TestNG Tutorials 36: Can a Test Method Return a Value in TestNG? – Make Selenium Easy Uncategorized
September 1, 2018 – Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark