Last active
June 6, 2023 20:54
-
-
Save mrzachhigginsofficial/839d46293fea9012c317143e2bec1cb7 to your computer and use it in GitHub Desktop.
Pytest Fixture - Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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