0
0
Selenium Pythontesting~10 mins

Conftest for shared fixtures in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses a shared fixture from conftest.py to open a browser, navigate to a page, and verify the page title. It checks that the fixture correctly provides the WebDriver instance.

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


def test_open_google(browser):
    browser.get('https://www.google.com')
    title = browser.title
    assert 'Google' in title

# conftest.py
import pytest
from selenium import webdriver

@pytest.fixture

def browser():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1PyTest starts and loads conftest.py to find fixturesPyTest environment ready with browser fixture available-PASS
2Test function test_open_google is called with browser fixture injectedBrowser fixture creates Chrome WebDriver instance-PASS
3Browser navigates to 'https://www.google.com'Chrome browser opens Google homepage-PASS
4Test retrieves page title from browserPage title is 'Google'Check if 'Google' is in page titlePASS
5Test asserts that 'Google' is in the page titleAssertion passes because title contains 'Google'assert 'Google' in titlePASS
6Test completes, browser fixture quits the WebDriverChrome browser closes-PASS
Failure Scenario
Failing Condition: Browser fixture fails to create WebDriver or page title does not contain 'Google'
Execution Trace Quiz - 3 Questions
Test your understanding
What does the browser fixture in conftest.py do?
AChecks the page title for correctness
BDefines the test function to run
CCreates and provides a WebDriver instance for tests
DCloses the browser after test completion
Key Result
Using a shared fixture in conftest.py helps reuse browser setup and teardown code across multiple tests, making tests cleaner and easier to maintain.