Skip to content

Instantly share code, notes, and snippets.

@mrzachhigginsofficial
Last active June 6, 2023 20:54
Show Gist options
  • Save mrzachhigginsofficial/839d46293fea9012c317143e2bec1cb7 to your computer and use it in GitHub Desktop.
Save mrzachhigginsofficial/839d46293fea9012c317143e2bec1cb7 to your computer and use it in GitHub Desktop.
Pytest Fixture - Selenium
import pytest
from selenium import webdriver
@pytest.fixture
def browser():
# Setup code
options = webdriver.FirefoxOptions()
options.headless = True # Run the browser in headless mode
driver = webdriver.Firefox(options=options)
yield driver # This is where the test runs
# Teardown code
driver.quit() # Close the browser and clean up resources
def test_example(browser):
# Use the browser instance provided by the fixture
browser.get("https://www.example.com") # Open a URL in the browser
# Perform Selenium actions and assertions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment