Challenge - 5 Problems
Conftest Fixture Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this pytest fixture usage?
Given the following
conftest.py fixture and test code, what will be printed when running test_example?Selenium Python
import pytest @pytest.fixture(scope="module") def browser(): print("Setup browser") yield "ChromeDriver" print("Teardown browser") def test_example(browser): print(f"Using {browser}") assert browser == "ChromeDriver"
Attempts:
2 left
💡 Hint
Remember that fixtures with yield run setup code before the test and teardown code after.
✗ Incorrect
The fixture runs the setup code first (prints 'Setup browser'), then the test runs (prints 'Using ChromeDriver'), and finally the teardown code runs (prints 'Teardown browser').
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the fixture value?
Assuming a fixture
driver returns a Selenium WebDriver instance, which assertion correctly checks the page title is 'Home'?Selenium Python
def test_title(driver): driver.get('http://example.com') # Which assertion is correct here?
Attempts:
2 left
💡 Hint
Check the Selenium WebDriver API for the page title property.
✗ Incorrect
The correct property to get the page title is
driver.title. Methods like get_title() or title() do not exist.❓ locator
advanced2:00remaining
Which locator is best for a shared fixture to find a login button?
In a shared fixture, you want to locate the login button reliably across tests. Which locator is best practice?
Attempts:
2 left
💡 Hint
IDs are unique and stable locators.
✗ Incorrect
Using the element's unique ID is the most reliable and fastest locator. Other options may be less stable or ambiguous.
🔧 Debug
advanced2:30remaining
Why does this fixture cause tests to fail intermittently?
Analyze the following fixture and explain why tests using it sometimes fail with a stale element error.
Selenium Python
import pytest @pytest.fixture(scope='function') def login(driver): driver.get('http://example.com/login') login_button = driver.find_element('id', 'login-btn') login_button.click() yield driver.quit()
Attempts:
2 left
💡 Hint
Consider what happens to the driver after the test finishes.
✗ Incorrect
Calling
driver.quit() in the fixture teardown closes the browser. If tests reuse elements or driver, stale element errors occur.❓ framework
expert3:00remaining
How to share a Selenium WebDriver instance across multiple test modules using conftest.py?
You want to create a shared Selenium WebDriver fixture in
conftest.py that opens the browser once per test session and closes it after all tests finish. Which fixture definition achieves this?Attempts:
2 left
💡 Hint
Consider fixture scope to control browser lifetime.
✗ Incorrect
Using
scope='session' creates the driver once per test session, sharing it across modules. Other scopes create or quit the driver more often.