0
0
Selenium Javatesting~10 mins

Hybrid framework architecture in Selenium Java - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test automates login functionality using a hybrid framework combining data-driven and keyword-driven approaches. It verifies successful login by checking the presence of a logout button.

Test Code - TestNG with Selenium WebDriver
Selenium Java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class HybridLoginTest {
    WebDriver driver;

    @BeforeClass
    public void setup() {
        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
    }

    @DataProvider(name = "loginData")
    public Object[][] loginData() {
        return new Object[][] {
            {"user1", "pass1"},
            {"user2", "pass2"}
        };
    }

    @Test(dataProvider = "loginData")
    public void testLogin(String username, String password) {
        driver.get("https://example.com/login");

        // Keyword-driven steps
        performAction("enterText", "id=username", username);
        performAction("enterText", "id=password", password);
        performAction("click", "id=loginBtn", null);

        // Assertion
        WebElement logoutBtn = driver.findElement(By.id("logoutBtn"));
        Assert.assertTrue(logoutBtn.isDisplayed(), "Logout button should be visible after login");
    }

    public void performAction(String action, String locator, String value) {
        By byLocator = getBy(locator);
        WebElement element = driver.findElement(byLocator);
        switch (action) {
            case "enterText":
                element.sendKeys(value);
                break;
            case "click":
                element.click();
                break;
            default:
                throw new IllegalArgumentException("Invalid action: " + action);
        }
    }

    public By getBy(String locator) {
        String[] parts = locator.split("=", 2);
        switch (parts[0]) {
            case "id":
                return By.id(parts[1]);
            case "name":
                return By.name(parts[1]);
            case "xpath":
                return By.xpath(parts[1]);
            default:
                throw new IllegalArgumentException("Invalid locator type: " + parts[0]);
        }
    }

    @AfterClass
    public void teardown() {
        if (driver != null) {
            driver.quit();
        }
    }
}
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test setup: ChromeDriver initialized and browser window maximizedChrome browser opened, ready for navigation-PASS
2Navigate to https://example.com/loginLogin page loaded with username, password fields and login buttonPage URL is correctPASS
3Find username field by id and enter 'user1'Username input filled with 'user1'Username field contains 'user1'PASS
4Find password field by id and enter 'pass1'Password input filled with 'pass1'Password field contains 'pass1'PASS
5Find login button by id and clickLogin form submitted, page loading user dashboard-PASS
6Find logout button by id to verify login successLogout button visible on dashboard pageLogout button is displayedPASS
7Repeat steps 2-6 for second data set: username 'user2', password 'pass2'Second login attempt successful, logout button visibleLogout button is displayedPASS
8Test teardown: Close browser and quit driverBrowser closed, WebDriver session ended-PASS
Failure Scenario
Failing Condition: Logout button not found after login attempt
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the logout button is visible on the page
BThat the login button is disabled
CThat the username field is cleared
DThat an error message appears
Key Result
Combining data-driven and keyword-driven techniques in a hybrid framework improves test flexibility and reusability by separating test data from test steps.