
📌Maven and Jenkins Integration with Selenium: What is Jenkins in Selenium?
Jenkins is an open-source continuous integration (CI) tool that automates the software development process. It helps developers by continuously building and testing applications in various environments, reducing manual effort.
Key Features of Jenkins:
- Automated Testing & Deployment – Runs tests and deploys software automatically after changes.
- Integration with Version Control – Supports SVN, Git, and other repositories for tracking changes.
- Easy Installation & Configuration – Simple setup on Windows, Linux, and Mac OS.
- Email Notifications – Sends build status reports to teams.
- Supports Plugins – Easily extend functionality with third-party plugins.
- TestNG Integration – Automates Selenium test execution.
Why Integrate Selenium with Jenkins?
- Automates execution of Selenium tests with each software update.
- Schedules test execution at specific times.
- Generates reports on test history and performance.
- Reduces manual testing effort and enhances software quality.
- Works seamlessly with Maven for dependency management.
📌What is Maven in Selenium?
Maven and Jenkins Integration with Selenium: Maven is a powerful build automation tool used for managing Selenium test projects. It helps in dependency management, project structure standardization, and automating the build process.
Advantages of Using Maven with Selenium
- Manages Dependencies – Automatically downloads required libraries.
- Standardized Project Structure – Ensures consistency in test projects.
- Automates Build & Test Execution – Reduces manual efforts.
- Supports TestNG & JUnit – Runs tests efficiently.
📌Maven Installation & Configuration in Eclipse
Step 1: Install Maven Plugin in Eclipse
- Open Eclipse and go to Help > Install New Software.
- Enter URL:
https://www.eclipse.org/m2e/
. - Select m2e Plugin and click Install.
Step 2: Create a Maven Project in Eclipse
- Go to File > New > Other > Maven > Maven Project.
- Select “Create a Simple Project” and click Next.
- Enter Group ID as
WebdriverTest
and Artifact ID asMavenProject
. - Click Finish to create the project.
Step 3: Add Dependencies in pom.xml
Modify the pom.xml
file and add the following dependencies:
xml<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
</dependency>
</dependencies>
📌Step 4: Create a TestNG Class
- Maven and Jenkins Integration with Selenium: In Eclipse, right-click on src/test/java and create a new package
example
. - Inside the package, create a new TestNG class named
NewTest.java
. - Add the following test script:
javaimport org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class NewTest {
@Test
public void testGoogleHomePage() {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
System.out.println("Title: " + driver.getTitle());
driver.quit();
}
}
- Convert the test class into TestNG format (
Right-click > Convert to TestNG
).
Step 5: Run Tests Using Maven
- Right-click on the project > Run As > Maven Test.
- Maven will download dependencies and execute the test script.
📌Jenkins Installation & Configuration for Selenium with Maven
Step 1: Install Jenkins
- Maven and Jenkins Integration with Selenium: Download Jenkins from
- Install Jenkins and start the service.
- Open
http://localhost:8080
in a browser to access Jenkins Dashboard.
Step 2: Create a New Jenkins Job
- Maven and Jenkins Integration with Selenium: Click New Item > Maven Project > Enter project name (
WebdriverTest
). - Click OK to create the job.
Step 3: Configure Maven & JDK in Jenkins
- Go to Manage Jenkins > Global Tool Configuration.
- Add JDK installation path.
- Add Maven installation path.
Step 4: Configure Jenkins Job for Selenium Execution
- In the Build section, enter:
- Root POM: Full path to
pom.xml
. - Goals & Options:
clean test
- Root POM: Full path to
- Click Save.
Step 5: Run Tests in Jenkins
- Click Build Now to trigger execution.
- Monitor build logs in Console Output.
- View Test Reports under Build History.
Automating Test Execution in Jenkins
Maven and Jenkins Integration with Selenium: To schedule automated test execution, configure Build Triggers:
- Schedule Daily Execution:
- Go to Build Triggers section.
- Enter
0 23 * * *
(Runs every day at 11 PM). - Click Apply & Save.
📌Running Selenium Tests in Jenkins Without Maven
Maven and Jenkins Integration with Selenium: If Maven is not used, execute TestNG scripts directly in Jenkins using:
shjava -cp "path/to/lib/*;path/to/bin" org.testng.TestNG testng.xml
- Modify paths accordingly before running.
- Jenkins will store results in a custom HTML report for email notifications.
📌Benefits of Using Jenkins for Selenium Automation
✅ Early Bug Detection – Continuous integration finds issues faster.
✅ Automated Test Execution – No manual intervention needed.
✅ Parallel Execution – Run tests on multiple environments.
✅ Report Generation – Stores test history & execution reports.
✅ Scalability – Supports distributed builds on multiple machines.
📌Conclusion
Maven and Jenkins Integration with Selenium: Integrating Jenkins with Maven & Selenium simplifies test execution, ensuring automated, scalable, and efficient testing. By following this guide, you can set up continuous integration, schedule tests, generate reports, and streamline automation workflows.
Let me know if you need customized configurations, troubleshooting tips, or best practices for Selenium-Jenkins integration!