Setup — Maven, pip & Project Structure
Set up a Selenium 4 project with Maven (Java) and pip (Python). Configure dependencies, project layout, and test runners.
Setting Up Your Selenium 4 Project
A clean project structure is the foundation of maintainable test automation. Java projects use Maven for dependency management, while Python uses pip. Both need proper folder layouts and test runner configuration.
Java with Maven
Maven handles dependency resolution, build lifecycle, and test execution. We'll use Selenium 4.x with TestNG as the test framework and WebDriverManager for automatic driver setup.
Python with pip
Python's simplicity makes setup quick — install selenium and pytest, create your folder structure, and you're ready to write tests. Selenium 4's built-in Selenium Manager removes the need for external driver management.
Selenium Manager (New in Selenium 4.6+)
Selenium Manager is a built-in tool that automatically downloads and configures the correct browser driver. No more manual ChromeDriver downloads or version mismatches. It works in both Java and Python out of the box.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.selenium.course</groupId>
<artifactId>selenium-course</artifactId>
<version>1.0.0</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<selenium.version>4.27.0</selenium.version>
<testng.version>7.10.2</testng.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Selenium 4 -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- TestNG -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<!-- WebDriverManager (optional — Selenium Manager is built in) -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
# Recommended Java project structure
selenium-course/
+-- pom.xml
+-- src/
| +-- test/
| +-- java/com/selenium/course/
| | +-- base/
| | | +-- BaseTest.java # Setup/teardown
| | +-- pages/
| | | +-- LoginPage.java # Page Objects
| | | +-- HomePage.java
| | +-- tests/
| | | +-- LoginTest.java # Test classes
| | | +-- NavigationTest.java
| | +-- utils/
| | +-- WaitHelper.java # Utilities
| | +-- ScreenshotUtil.java
| +-- resources/
| +-- testng.xml
| +-- config.properties
+-- test-output/ # Reports
# requirements.txt
selenium==4.27.0
pytest==8.3.4
pytest-html==4.1.1
webdriver-manager==4.0.2
python-dotenv==1.0.1
# Recommended Python project structure
selenium-course/
+-- requirements.txt
+-- pytest.ini
+-- conftest.py # Shared fixtures
+-- config/
| +-- __init__.py
| +-- settings.py # URLs, timeouts
+-- pages/
| +-- __init__.py
| +-- login_page.py # Page Objects
| +-- home_page.py
+-- tests/
| +-- __init__.py
| +-- test_login.py # Test files
| +-- test_navigation.py
+-- utils/
| +-- __init__.py
| +-- wait_helper.py # Utilities
| +-- screenshot_util.py
+-- reports/ # HTML reports
# conftest.py — shared pytest fixtures
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
@pytest.fixture(scope='function')
def driver():
"""Create a fresh browser instance for each test."""
options = Options()
# options.add_argument('--headless=new') # Uncomment for headless
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1920,1080')
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(10)
yield driver
driver.quit()
@pytest.fixture(scope='session')
def base_url():
return 'https://www.selenium.dev/'
Written by PV
© 2026 All Rights Reserved