0
0
Selenium Pythontesting~10 mins

Parallel execution in CI in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs two simple Selenium tests in parallel using pytest-xdist in a Continuous Integration (CI) environment. It verifies that both tests open the browser, navigate to the page, and check the page title independently and simultaneously.

Test Code - pytest with pytest-xdist
Selenium Python
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By

@pytest.fixture(scope="function")
def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()

@pytest.mark.parametrize("url,expected_title", [
    ("https://example.com", "Example Domain"),
    ("https://www.python.org", "Welcome to Python.org")
])
def test_parallel_execution(driver, url, expected_title):
    driver.get(url)
    assert driver.title == expected_title
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts with pytest-xdist to run tests in parallelCI environment ready to run tests concurrently-PASS
2Two browser instances open simultaneously using webdriver.Chrome()Two Chrome browsers launched independently-PASS
3Each browser navigates to its assigned URL (example.com and python.org)Browser 1 shows example.com, Browser 2 shows python.org-PASS
4Each test checks the page title matches expected titleBrowser 1 title is 'Example Domain', Browser 2 title is 'Welcome to Python.org'Assert driver.title == expected_title for each testPASS
5Each browser instance closes after test completionNo browsers remain open-PASS
6Pytest reports both tests passed in parallelCI console shows both tests passed with no errorsTest report shows 2 passed testsPASS
Failure Scenario
Failing Condition: One browser fails to open or navigate, or title assertion fails
Execution Trace Quiz - 3 Questions
Test your understanding
What does pytest-xdist do in this test?
ARuns tests only on one browser instance
BRuns tests sequentially one after another
CRuns tests in parallel to speed up execution
DSkips tests that fail
Key Result
Running tests in parallel in CI saves time but requires each test to be independent with its own browser instance to avoid interference.