Skip to content
Tutorials Center
My learning

Topics

Lesson 50 of 60 ยท Automation Concepts and Process

Automation Frameworks: Data-Driven, Keyword-Driven, Hybrid and POM

Learn test automation framework types: linear, modular, data-driven, keyword-driven, hybrid and BDD, and the Page Object Model, with runnable examples.

When you automate a handful of tests, you can write each as a script that clicks and checks. After a hundred, problems appear: the same login steps are copied everywhere, a changed button breaks forty scripts, and adding test data means editing code. A test automation framework is the set of structure, conventions and helper libraries that keeps automation manageable. It is not a tool; it is a way of organizing tests so that they are reusable, readable and cheap to maintain.

This lesson walks through the main framework styles and the Page Object Model, the most important pattern for UI tests. It follows When to Automate.

What a framework provides

A good framework usually offers:

  • A folder structure and naming convention.
  • Reusable functions for common actions (log in, create user, wait for element).
  • Separation of test data from test logic.
  • Configuration for environments, browsers and credentials.
  • Reporting and logging, screenshots on failure.
  • Integration with the test runner and CI (see the next lessons).
  • Rules for waiting, retries and cleanup.

Framework types

Linear (record and playback)

Steps are recorded or written top to bottom in a single script, with data hard-coded. Quick to start, useless for scale: no reuse, and any change means re-recording. Fine for a throw-away prototype or a quick demo.

Modular

The application is split into modules, and each gets reusable functions (login, search, checkout). Test scripts call these. When the login page changes, you fix one function. This is the first step toward maintainability.

Data-driven

The same test logic runs against many data rows from an external source such as a CSV file, spreadsheet, JSON or database. Add a row, get a new test case. It fits the output of equivalence partitioning and boundary value analysis: many inputs, one procedure.

Keyword-driven (action-word)

Tests are written as tables of keywords (OpenBrowser, Login, Click, VerifyText) with arguments. Each keyword is implemented once in code. Non-programmers can compose tests from the keyword table, while engineers maintain the keywords. Robot Framework is a well-known example.

Hybrid

Most real frameworks mix the above: modular functions, data files and keywords where they fit.

BDD frameworks

Tests are scenarios in plain language (Given, When, Then) with step definitions underneath; see TDD vs BDD.

Style Reuse Test data Who writes tests Maintenance
Linear None Hard-coded Anyone Poor
Modular Functions Mostly in code Programmers Good
Data-driven Same script, many rows External files Programmers plus data authors Good
Keyword-driven Keywords Tables Non-programmers can compose Good, needs a keyword library
Hybrid Mixed Mixed Mixed Depends on discipline
BDD Steps In scenarios Whole team Good if scenarios stay clean

Try it: data-driven in action

One test procedure, many data rows. Adding a case means adding one line of data, not code. The "table" could just as well come from a CSV file.

JS A data-driven discount test

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Try it: keyword-driven in action

Here the test is a table of keywords. The engine looks up each keyword's implementation. The Login keyword hides several steps; if the login flow changes, only its definition changes.

JS A keyword-driven test engine

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The Page Object Model (POM)

UI automation scripts find elements with locators (id, CSS selector, text). If every test repeats click("#btn-login-2"), a renamed button breaks every test. The Page Object Model fixes that with one rule: each page (or component) of the application gets a class that owns its locators and exposes actions in business language. Tests call the page object's methods; they never touch locators.

flowchart LR
  T["Test<br/>login and check welcome"] --> LP["LoginPage<br/>enterUser, enterPassword, submit"]
  T --> DP["DashboardPage<br/>welcomeText"]
  LP --> L["Locators and low-level browser actions"]
  DP --> L

Tests read like a story. If the login page changes, only LoginPage is edited.

Benefits:

  • One place to fix when the UI changes.
  • Readable tests, written in the vocabulary of the user.
  • Less duplication, since methods like login() are shared.
  • A clear split between what is tested (in the test) and how the page is driven (in the page object).

Rules of thumb:

  • Page object methods do actions and return data or the next page object; assertions stay in tests (or in separate verification helpers).
  • Model meaningful components (header, search box, cart) as their own objects, not only whole pages.
  • Keep waits inside the page object so tests are not full of sleeps (see flaky tests).

A close cousin, the Screenplay pattern, models tests as actors performing tasks, and is popular where POM classes grow too large.

Try it: a page object over a fake page

We simulate a "browser" as an object with elements, so the POM idea can be seen without a real browser. Notice that the test never mentions a locator.

JS Page Object Model with a fake browser

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Choosing a framework in practice

You rarely write one from nothing. Start from a runner and library your team knows (JUnit or TestNG with Selenium, Playwright Test, Cypress, pytest with Selenium, Robot Framework) and add structure:

  1. Start modular with page objects for UI tests; test APIs directly where you can.
  2. Add data-driven tests where the logic is the same and the data varies.
  3. Use keywords or BDD only if non-programmers will actually write tests; otherwise they add a layer for nothing.
  4. Keep tests independent (own data, own state), so they can run in parallel.
  5. Put reports and screenshots on failure in from the beginning.
  6. Review the framework like production code: small functions, no duplication, version control.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a data-driven framework, what changes when you add a new test case?

    The test procedure stays the same; extra data rows create extra cases.
  2. 2. What is the main idea of a keyword-driven framework?

    Keywords such as Login or Verify Text are implemented once, then assembled into tests, possibly by non-programmers.
  3. 3. What is the Page Object Model's main benefit?

    Page objects encapsulate how a page is driven, reducing duplication and maintenance.
  4. 4. Where should assertions usually be placed in the Page Object Model?

    Page objects expose actions and data. Tests decide what is correct, which keeps page objects reusable.

Summary

  • A framework is the structure around automation: conventions, reusable functions, data handling, configuration and reporting.
  • Linear scripts do not scale; modular, data-driven, keyword-driven, hybrid and BDD styles add reuse and separation.
  • The Page Object Model keeps locators and page actions in dedicated classes so tests stay readable and UI changes are cheap to absorb.
  • Start simple and add structure where it removes duplication or brings in non-programmers.

Next up: Selenium, Cypress and Headless Browsers.