State differences between Data Driven and Keyword Driven Framework.

Data Driven and Keyword Driven frameworks are two popular approaches in test automation. Understanding their differences helps choose the right framework for your testing needs.

Data Driven Framework

In data driven testing, we run tests on multiple data sets using parameterization. The data acts as input to the test script logic, with each data set representing a separate test case.

The framework revolves around data maintained in external files (Excel, CSV, JSON) which is updated for individual test cases without changing the core test script logic.

Example: Data Driven Login Test

// Sample data structure for login testing
const loginData = [
    { username: "user1@test.com", password: "pass123", expected: "success" },
    { username: "invalid@test.com", password: "wrongpass", expected: "failure" },
    { username: "admin@test.com", password: "admin123", expected: "success" }
];

// Test function that uses the data
function testLogin(testData) {
    console.log(`Testing login with: ${testData.username}`);
    // Test logic would go here
    console.log(`Expected result: ${testData.expected}`);
}

// Run tests for all data sets
loginData.forEach((data, index) => {
    console.log(`Test Case ${index + 1}:`);
    testLogin(data);
    console.log("---");
});
Test Case 1:
Testing login with: user1@test.com
Expected result: success
---
Test Case 2:
Testing login with: invalid@test.com
Expected result: failure
---
Test Case 3:
Testing login with: admin@test.com
Expected result: success
---

Keyword Driven Framework

In keyword driven testing, keywords represent specific actions. A sequence of keywords forms a complete test case. Once developed, keywords can be reused across multiple test scripts.

This framework allows both automation and manual testers to contribute, as test cases are defined using readable keywords in external files rather than code.

Example: Keyword Driven Test Structure

// Sample keyword-driven test structure
const testSteps = [
    { keyword: "OPEN_BROWSER", data: "chrome" },
    { keyword: "NAVIGATE_TO", data: "https://example.com/login" },
    { keyword: "ENTER_TEXT", data: "username|user@test.com" },
    { keyword: "ENTER_TEXT", data: "password|mypassword" },
    { keyword: "CLICK_BUTTON", data: "login" },
    { keyword: "VERIFY_TEXT", data: "Welcome" },
    { keyword: "CLOSE_BROWSER", data: "" }
];

// Keyword execution engine
function executeKeyword(step) {
    console.log(`Executing: ${step.keyword} with data: ${step.data}`);
    
    switch(step.keyword) {
        case "OPEN_BROWSER":
            console.log(`Opening ${step.data} browser`);
            break;
        case "NAVIGATE_TO":
            console.log(`Navigating to ${step.data}`);
            break;
        case "ENTER_TEXT":
            const [field, value] = step.data.split('|');
            console.log(`Entering '${value}' in ${field} field`);
            break;
        case "CLICK_BUTTON":
            console.log(`Clicking ${step.data} button`);
            break;
        case "VERIFY_TEXT":
            console.log(`Verifying text: ${step.data}`);
            break;
        case "CLOSE_BROWSER":
            console.log("Closing browser");
            break;
        default:
            console.log("Unknown keyword");
    }
}

// Execute all test steps
testSteps.forEach(step => executeKeyword(step));
Executing: OPEN_BROWSER with data: chrome
Opening chrome browser
Executing: NAVIGATE_TO with data: https://example.com/login
Navigating to https://example.com/login
Executing: ENTER_TEXT with data: username|user@test.com
Entering 'user@test.com' in username field
Executing: ENTER_TEXT with data: password|mypassword
Entering 'mypassword' in password field
Executing: CLICK_BUTTON with data: login
Clicking login button
Executing: VERIFY_TEXT with data: Welcome
Verifying text: Welcome
Executing: CLOSE_BROWSER with data: 
Closing browser

Key Differences

Aspect Data Driven Keyword Driven
Focus Test data variations Reusable test actions
Maintenance Update data files Update keyword definitions
Team Collaboration Primarily automation testers Both manual and automation testers
Flexibility Easy data modification Easy test flow modification
Complexity Lower implementation complexity Higher initial setup complexity

When to Use Each Framework

Data Driven: Choose when you need to test the same functionality with multiple input combinations, such as login testing with different user credentials.

Keyword Driven: Choose when you need maximum reusability and want non-technical team members to contribute to test creation and maintenance.

Conclusion

Data Driven frameworks excel at testing multiple data combinations, while Keyword Driven frameworks provide better reusability and team collaboration. Choose based on your testing requirements and team structure.

Updated on: 2026-03-15T23:18:59+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements