</>

Technology

Selenium

Difficulty

Beginner

Interview Question

What are the open-source frameworks supported by Selenium WebDriver?

Selenium WebDriver integrates with JUnit, TestNG, Cucumber (BDD), and JBehave (BDD) as open-source testing frameworks for Java-based Selenium projects.

Answer

Open-Source Frameworks Supported by Selenium WebDriver

Selenium WebDriver integrates with several open-source testing frameworks to provide assertions, test lifecycle management, and reporting.

Primary frameworks:

1. JUnit The classic Java unit testing framework. Simple and widely used.

Java
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import static org.junit.Assert.*;

public class LoginTest {

    @Before
    public void setUp() {
        driver = new ChromeDriver();
    }

    @Test
    public void testLogin() {
        driver.get("https://example.com/login");
        assertEquals("Login Page", driver.getTitle());
    }

    @After
    public void tearDown() {
        driver.quit();
    }
}

2. TestNG (most popular for Selenium) Feature-rich testing framework with parallel execution, grouping, and data providers.

Java
import org.testng.annotations.*;
import org.testng.Assert;

public class LoginTest {

    @BeforeClass
    public void setUp() { driver = new ChromeDriver(); }

    @Test(groups = "regression", dataProvider = "loginData")
    public void loginTest(String user, String pass) {
        Assert.assertEquals(driver.getTitle(), "Dashboard");
    }

    @AfterClass
    public void tearDown() { driver.quit(); }
}

3. Cucumber (BDD — Behavior-Driven Development) Write tests in plain English (Gherkin syntax) with step definitions in Java.

Gherkin
Feature: Login functionality
  Scenario: Valid login
    Given I am on the login page
    When I enter "admin" and "password"
    Then I should see "Dashboard"
Java
@Given("I am on the login page")
public void iAmOnLoginPage() {
    driver.get("https://example.com/login");
}

4. JBehave (BDD framework) Another BDD framework similar to Cucumber, uses story files.

STORY
Given I navigate to login page
When I enter username admin and password password
Then I should be redirected to dashboard

Framework comparison:

FrameworkStyleBest for
JUnitAnnotation-basedSimple unit/integration tests
TestNGAnnotation-basedComplex Selenium suites
CucumberBDD (Gherkin)Non-technical stakeholders
JBehaveBDD (story files)BDD with story-format specs

Key list:

  1. JUnit
  2. TestNG
  3. CUCUMBER
  4. JBEHAVE

Follow AutomateQA

Related Topics