Advanced Chapter 18 · 12 min read

Parallel Execution & Reporting

Run tests in parallel to cut execution time. Generate Allure, Extent, and HTML reports. Integrate with TestNG suites and pytest-xdist.

Parallel Execution & Reporting

Sequential test execution is slow. Parallel execution cuts total time dramatically by running tests simultaneously across multiple threads or processes. Coupled with rich reports, you get fast feedback with full visibility.

testng-parallel.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">

<!-- Run tests in parallel across 4 threads -->
<suite name="Parallel Suite" parallel="methods" thread-count="4">
    <test name="All Tests">
        <classes>
            <class name="com.selenium.course.tests.LoginTest"/>
            <class name="com.selenium.course.tests.NavigationTest"/>
            <class name="com.selenium.course.tests.FormTest"/>
        </classes>
    </test>
</suite>

<!-- parallel options: methods, tests, classes, instances -->
<!-- thread-count: number of concurrent threads -->
pom-reporting.xml
<!-- Add to pom.xml for Allure + ExtentReports -->
<dependencies>
    <!-- Allure TestNG -->
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-testng</artifactId>
        <version>2.25.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>io.qameta.allure</groupId>
            <artifactId>allure-maven</artifactId>
            <version>2.12.0</version>
            <configuration>
                <reportVersion>2.25.0</reportVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.2.5</version>
            <configuration>
                <parallel>methods</parallel>
                <threadCount>4</threadCount>
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
    </plugins>
</build>

<!-- Run: mvn clean test -->
<!-- Report: mvn allure:serve -->
pytest-parallel.ini
# pytest.ini — parallel execution config
[pytest]
testpaths = tests
addopts =
    -v
    --tb=short
    -n auto
    --html=reports/report.html
    --self-contained-html

# -n auto: pytest-xdist auto-detects CPU cores
# -n 4: use exactly 4 parallel workers

# Install: pip install pytest-xdist pytest-html

# Run parallel:
#   pytest -n auto
#   pytest -n 4
#   pytest -n auto --browser=chrome --headless

markers =
    smoke: Quick smoke tests
    regression: Full regression
    parallel: Safe for parallel execution
conftest_reporting.py
"""Enhanced conftest.py with reporting hooks"""
import pytest, os, datetime
from selenium import webdriver

@pytest.fixture(scope='function')
def driver():
    d = webdriver.Chrome()
    d.implicitly_wait(10)
    d.maximize_window()
    yield d
    d.quit()

# Screenshot on failure for HTML report
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()

    if report.when == "call" and report.failed:
        driver = item.funcargs.get("driver")
        if driver:
            timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
            os.makedirs("reports/screenshots", exist_ok=True)
            path = f"reports/screenshots/{item.name}_{timestamp}.png"
            driver.save_screenshot(path)

            # Attach to HTML report
            if hasattr(report, 'extra'):
                from pytest_html import extras
                report.extra.append(extras.image(path))

# Run:
#   pytest --html=reports/report.html -n auto
#   pytest -m smoke --html=reports/smoke.html

Selenium Advanced Parallel Execution & Reporting

Written by PV

© 2026 All Rights Reserved