#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Jenkins & CI/CD

Dependencies and configure Maven Project (Selenium)

Setting Up the Project

Create a Maven project in Eclipse, then declare the libraries the Selenium suite needs inside pom.xml, letting Maven automatically download and manage them.

Typical Dependencies

<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.9.0</version>
  </dependency>
</dependencies>

Why This Matters

Once these dependencies are declared, every class in the project can immediately use Selenium's WebDriver API and TestNG's annotations, without manually downloading or managing any jar files.

A Complete pom.xml for a Selenium Suite

Keeping versions in a properties block makes upgrades a one-line change, and the test scope keeps testing libraries out of any packaged application.

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.qa</groupId>
  <artifactId>web-ui-tests</artifactId>
  <version>1.0.0</version>

  <properties>
    <maven.compiler.release>17</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <selenium.version>4.21.0</selenium.version>
    <testng.version>7.9.0</testng.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>${selenium.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>${testng.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

The maven.compiler.release property tells the compiler which Java version to target; it must not be higher than the JDK installed on the machine or the Jenkins agent. If page objects live in src/main/java rather than under test sources, drop the test scope so that code can see Selenium classes.

Where files go in the project

web-ui-tests/
  pom.xml
  testng.xml
  src/test/java/com/example/qa/pages/LoginPage.java
  src/test/java/com/example/qa/tests/LoginTest.java
  src/test/resources/config.properties

Maven builds by convention, so classes placed outside these folders will not compile or run without extra configuration. Files in src/test/resources are copied onto the test classpath, which means setup code can load config.properties with getClass().getResourceAsStream("/config.properties") instead of a hardcoded disk path. That small habit is what lets the same project run unchanged on a laptop and on a Jenkins agent.

Commands You Will Use Every Day

mvn clean test                 # fresh build and run all tests
mvn dependency:tree            # show every library, including transitive ones
mvn -U clean test              # force Maven to recheck remote repositories
mvn test -Dheadless=true       # pass a flag that your setup code reads

dependency:tree is the quickest way to solve version conflicts, for example two different versions of the same HTTP library brought in by separate dependencies. Downloaded jars are cached in the local repository under the .m2 folder in your home directory, so later builds work offline unless versions change.

Running the Project From Jenkins

Because the POM describes everything, a CI server needs only a JDK, Maven and the repository. A simple declarative pipeline looks like this:

pipeline {
    agent any
    tools { maven 'Maven3' }
    stages {
        stage('Checkout') { steps { checkout scm } }
        stage('UI Tests') { steps { sh 'mvn clean test -Dheadless=true' } }
    }
    post {
        always { junit 'target/surefire-reports/*.xml' }
    }
}

The name Maven3 must match a Maven installation configured in Jenkins' global tool settings. The junit step publishes test results so failures show up as trends on the job page. On Windows agents, replace sh with bat.

Problems You Are Likely to Hit

  • Red imports in the IDE after editing the POM. Reload or update the Maven project so the IDE downloads the new libraries.
  • "package org.openqa.selenium does not exist". Usually code in src/main/java while the dependency has test scope.
  • Corporate proxy blocking downloads. Configure the proxy in Maven's settings.xml instead of copying jar files by hand.
  • Adding a separate driver-manager library unnecessarily. Recent Selenium versions locate browser drivers themselves through Selenium Manager.
  • No browser on the build agent. Jenkins machines need Chrome or another browser installed, and usually run headless.

Ready to master real-world software testing?

Learn manual and automation testing hands-on with mentor-led sessions.

Explore Course