Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How do I integrate Selenium with other tools and frameworks?

Selenium WebDriver only automates the browser, so you integrate it by wiring other tools around it: a test runner (TestNG or JUnit) to structure and execute tests, a build tool (Maven or Gradle) to manage dependencies, an optional BDD layer (Cucumber), a reporting library (Allure or ExtentReports), a CI/CD service (Jenkins, GitHub Actions, or GitLab) to run everything automatically, and a Selenium Grid to run in parallel across browsers. In practice, integration means adding the right dependency and calling Selenium from inside that tool. The sections below show how for each.

Why Selenium Needs Other Tools

Selenium is intentionally narrow. The WebDriver API gives you commands to open a browser, find elements, click, type, and read the page, and nothing else. It has no concept of a test case, no assertions, no report, no retry logic, and no way to trigger itself on a code push. That minimalism is a strength, because it lets you assemble exactly the stack your team prefers, but it means a usable test suite is always Selenium plus several companion tools.

If you want a deeper look at where these gaps come from, see Why Can Selenium Not Integrate with Other Tools and Frameworks?. This guide focuses on the practical side: which tool fills each gap and how to connect it.

Integrate Selenium With Test Runners (TestNG, JUnit)

A test runner gives Selenium a lifecycle, groups, parallelism, and pass/fail reporting. In the Java world the two standard choices are TestNG and JUnit.

  • TestNG: Drive the WebDriver lifecycle from annotations. Create the driver in @BeforeMethod, run interactions and assertions in @Test, and quit the driver in @AfterMethod. Suites, groups, parallel runs, and data providers are configured in a testng.xml file.
  • JUnit: The same pattern using JUnit 5 annotations, @BeforeEach, @Test, and @AfterEach, executed by the Maven Surefire or Gradle test task.

A minimal TestNG-driven Selenium test looks like this:

public class LoginTest {
    WebDriver driver;

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

    @Test
    public void verifyTitle() {
        driver.get("https://example.com");
        Assert.assertEquals(driver.getTitle(), "Example Domain");
    }

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

Integrate Selenium With Build Tools (Maven, Gradle)

Build tools pull in Selenium and its companions as managed dependencies and give you a single command to compile and run the suite. This is also what makes CI/CD integration trivial later, since the pipeline just calls the same command.

  • Maven: Declare selenium-java and your runner in pom.xml; run the suite with mvn test, which executes it through the Surefire plugin.
  • Gradle: Add testImplementation dependencies in build.gradle and run gradle test, selecting the runner with useTestNG() or useJUnitPlatform().

A Maven dependency block that wires Selenium to TestNG:

<dependencies>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.21.0</version>
  </dependency>
  <dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>7.10.2</version>
    <scope>test</scope>
  </dependency>
</dependencies>

Integrate Selenium With BDD (Cucumber)

Cucumber lets non-technical stakeholders read and write tests in plain-language Gherkin. You describe behaviour in .feature files, then map each Gherkin step to a Java step definition that calls Selenium WebDriver. A runner (Cucumber with TestNG or JUnit) glues the two together.

// login.feature
// Scenario: Valid login
//   Given I open the login page
//   When I sign in as a valid user

@Given("I open the login page")
public void openLoginPage() {
    driver.get("https://example.com/login");
}

Add the cucumber-java and cucumber-testng (or cucumber-junit) dependencies, and Cucumber runs as part of the same Maven or Gradle build.

Integrate Selenium With Reporting (Allure, ExtentReports)

  • Allure: Add the allure-testng or allure-cucumber adapter; results are written during the run, and allure serve builds an interactive HTML report with steps, attachments, and screenshots.
  • ExtentReports: Create an ExtentReports object and an ExtentTest per test, log step status and screenshots, then call flush() to write a standalone HTML report.

Because Selenium has no native reporting, these libraries are what turn a raw pass/fail into something a team can triage.

Integrate Selenium With CI/CD (Jenkins, GitHub Actions, GitLab)

Once your tests run through Maven or Gradle, the CI server only has to invoke that one command on every push or schedule, then publish the report.

  • Jenkins: A freestyle job or pipeline stage runs mvn clean test; the Allure or HTML Publisher plugin surfaces the report on the build page.
  • GitHub Actions: A workflow uses actions/setup-java, then a step running mvn -B test, triggered on push or pull request.
  • GitLab CI: A .gitlab-ci.yml test job whose script is mvn -B test, with the report kept as an artifact.

A Jenkins declarative pipeline stage is as small as this:

pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        sh 'mvn clean test'
      }
    }
  }
}

Run Selenium at Scale With Grid and the Cloud

To run tests in parallel and across multiple browsers, you point Selenium at a Grid instead of a local driver. A self-hosted What Is Selenium Grid? is a hub plus nodes that you install and maintain. Either way, your test code talks to it through the RemoteWebDriver class and a desired-capabilities object.

ChromeOptions options = new ChromeOptions();
options.setBrowserVersion("latest");

WebDriver driver = new RemoteWebDriver(
    new URL("https://hub.example.com/wd/hub"), options);

The same code works against a cloud grid; you only swap the hub URL and credentials. A cloud Selenium Grid Online lets you run across thousands of real browser and OS combinations in parallel without provisioning or maintaining any infrastructure, which is the simplest way to scale a Selenium suite. To understand what sits behind that RemoteWebDriver call, see How Does a WebDriver Work?

Supporting Integrations Worth Knowing

  • Page Object Model: A design pattern, not a dependency. One class per page wraps that page's locators and actions, so tests call readable methods and locator changes live in one place.
  • Assertion libraries: Selenium has no assertions, so you use your runner's Assert, or a fluent library such as AssertJ or Hamcrest, to verify expected state.
  • Data-driven with Apache POI: Read an Excel sheet with poi-ooxml and feed each row into a TestNG @DataProvider so one test runs across many data sets.
  • Logging with Log4j: Add log4j-core with a log4j2.xml config and a LogManager.getLogger() instance to trace each step and capture failures.
  • Docker: Run the Grid as containers via a docker-compose file (hub plus browser nodes) to isolate browser versions and parallelize cleanly in CI.
  • Language bindings: Use the official client for your language, Java, Python, JavaScript, C#, or Ruby, and that ecosystem's tools, for example pytest with Python or Mocha with selenium-webdriver in JavaScript.

Quick Reference: Selenium Integration Stack

LayerToolsHow to integrate
Test runnerTestNG, JUnitCall WebDriver from annotated lifecycle methods
Build toolMaven, GradleDeclare dependencies; run with mvn test / gradle test
BDDCucumberMap Gherkin steps to Selenium step definitions
ReportingAllure, ExtentReportsAdd the adapter; generate HTML from results
CI/CDJenkins, GitHub Actions, GitLabTrigger mvn clean test on push; publish the report
ScaleSelenium Grid, cloud grid, DockerRun via RemoteWebDriver against a hub URL
Data and loggingApache POI, Log4jFeed data via @DataProvider; trace steps via loggers

Frequently Asked Questions

Does Selenium have a built-in test runner or reporting?

No. Selenium WebDriver only automates the browser. It has no test runner, assertion library, reporting engine, or CI hook of its own. You add a runner such as TestNG or JUnit, a reporting library such as Allure or ExtentReports, and a CI tool such as Jenkins. Integration simply means adding those dependencies and calling Selenium from inside them.

How do I integrate Selenium with TestNG?

Add the TestNG dependency to your build file, then drive the WebDriver lifecycle from TestNG annotations: start the driver in @BeforeMethod, run interactions and assertions in @Test, and quit it in @AfterMethod. Parallel execution and data providers are configured in the testng.xml suite file.

How does Selenium connect to a CI/CD pipeline?

Your tests are wrapped in a build tool such as Maven or Gradle, so the CI server only needs to run a single command like mvn clean test. Jenkins, GitHub Actions, and GitLab CI each trigger that command on push or on a schedule, then publish the generated Allure or HTML report as a build artifact.

What is the difference between Selenium Grid and a cloud Selenium grid?

Both are driven through the same RemoteWebDriver class. A self-hosted Selenium Grid is a hub and nodes you install and maintain yourself. A cloud Selenium grid points that same RemoteWebDriver URL at a managed endpoint, so you can run across thousands of browser and OS combinations in parallel without provisioning any machines.

Can I do data-driven testing with Selenium?

Yes, but the data layer is separate from Selenium. A common approach is to read an Excel sheet with Apache POI, or a CSV/JSON file, and feed each row into a TestNG @DataProvider so the same Selenium test runs once per data set.

Which programming languages can I use to integrate Selenium?

Selenium ships official client bindings for Java, Python, JavaScript, C#, and Ruby. You pick the binding for your language and use that ecosystem's tooling, for example Maven and TestNG with Java, pytest with Python, or Mocha with selenium-webdriver in JavaScript.

Related Questions

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests