Framework Types - Notes By ShariqSP

Framework Types

Types of Frameworks in Selenium

Selenium offers different types of frameworks to streamline and organize the process of automated testing. Each framework serves a specific purpose and is suitable for different use cases depending on the complexity, reusability, and maintainability of the test scripts. Below are the commonly used frameworks in Selenium, along with explanations of when and where to use each, supported by real-time scenarios.

1. Modular Framework

The modular framework is based on the concept of breaking down the application under test into smaller, independent modules. Each module is tested independently, and the test scripts for each module are created separately. This approach makes it easier to update and maintain specific parts of the application without affecting other areas.

When to Use:

Use this framework when the application can be logically divided into smaller units or modules, and the changes to one module should not impact other parts of the system.

Real-Time Scenario:

In an e-commerce application, different modules such as user login, product search, checkout, and payment can be tested independently. Each module has its own set of test cases that are isolated from one another, making it easier to update the product search functionality without affecting the login or payment tests.

2. Data-Driven Framework

In a Data-Driven Framework, the test logic is separated from the test data. The test scripts are driven by external data, often stored in files like Excel, CSV, or databases. The same test script can be executed with multiple sets of data, making it ideal for scenarios that involve repeated testing with different inputs.

When to Use:

Use this framework when you need to test the same functionality with multiple sets of data. This is ideal for applications where the input data changes frequently.

Real-Time Scenario:

Consider a banking application where the same login functionality needs to be tested with different sets of user credentials. A data-driven framework can be used to run the same login test case with multiple sets of usernames and passwords stored in an Excel sheet. This ensures that the login works for all types of users (e.g., admins, regular users, or guests).

3. Keyword-Driven Framework

The Keyword-Driven Framework separates the test execution logic from the test scripts by using keywords. Each keyword represents an action to be performed (e.g., "Click", "Enter", "Verify"). The keywords are defined in an external file, such as an Excel sheet, and the framework interprets and executes them.

When to Use:

This framework is useful when non-technical team members need to contribute to test case creation, as it simplifies the process by using keywords instead of complex code.

Real-Time Scenario:

For a retail website, you can create a keyword-driven framework where testers or business analysts can define actions like "Open Browser", "Enter Text", "Click Button", or "Verify Title" in an Excel sheet. The framework will then execute these keywords without requiring the testers to write actual code.

4. Hybrid Framework

A Hybrid Framework combines the features of different frameworks, typically merging Data-Driven and Keyword-Driven approaches. It leverages the advantages of both frameworks, allowing for flexibility and scalability in test execution.

When to Use:

Use this framework when you need to handle both data-driven scenarios and keyword-driven scenarios, allowing both technical and non-technical users to contribute.

Real-Time Scenario:

Imagine a travel booking application where you want to test different booking workflows (e.g., flight booking, hotel booking) using a set of keywords. Additionally, you need to test these workflows with different sets of data (e.g., different cities, hotels, flight options). A hybrid framework allows the testers to define both keywords and data in external files, making the tests reusable and flexible.

5. Behavior-Driven Development (BDD) Framework

The BDD Framework focuses on writing test cases in a human-readable language, making it easier for non-technical stakeholders (like business analysts) to understand the functionality being tested. BDD is often implemented using tools like Cucumber with Gherkin syntax, where test cases are written in plain English and structured with "Given", "When", and "Then" statements.

When to Use:

Use BDD when you want to involve non-technical stakeholders in the testing process and need tests to be easily understandable by everyone on the team.

Real-Time Scenario:

For a healthcare application, stakeholders like product managers or business analysts may want to ensure that user workflows are functioning as expected. Using BDD with Gherkin, you can write scenarios like:
Given the user is on the login page,
When the user enters valid credentials and clicks login,
Then the user should be redirected to the dashboard.

This makes it easier for all stakeholders to verify that the application behaves as intended without diving into technical details.

Choosing the Right Framework

The choice of framework depends on the application under test and the team's technical expertise. Here's a quick guide to help you decide:

  • Modular Framework: Use when the application can be divided into independent modules.
  • Data-Driven Framework: Use when testing the same functionality with different data sets.
  • Keyword-Driven Framework: Use when non-technical team members need to create test cases using keywords.
  • Hybrid Framework: Use when you need flexibility and a combination of data-driven and keyword-driven features.
  • BDD Framework: Use when you want tests to be written in a way that can be understood by all stakeholders, including non-technical members.