Challenge - 5 Problems
Selenium pytest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest fixture with Selenium WebDriver
What will be the output when running this pytest test with the given fixture?
Selenium Python
import pytest from selenium import webdriver @pytest.fixture async def driver(): driver = webdriver.Firefox() yield driver driver.quit() def test_title(driver): driver.get('https://example.com') assert 'Example Domain' in driver.title print('Test Passed')
Attempts:
2 left
💡 Hint
pytest fixtures should not be async unless using pytest-asyncio plugin
✗ Incorrect
The fixture is declared async but webdriver.Firefox() is synchronous. pytest does not support async fixtures by default, causing a SyntaxError or runtime error.
❓ assertion
intermediate1:30remaining
Correct assertion for page title in Selenium test
Which assertion correctly verifies the page title contains 'Welcome' in a Selenium test using pytest?
Selenium Python
def test_page_title(driver): driver.get('https://mysite.com') # Choose the correct assertion below
Attempts:
2 left
💡 Hint
Use Python's 'in' keyword to check substring presence
✗ Incorrect
Option D uses Python's 'in' keyword correctly to check if 'Welcome' is part of the title string. Option D requires exact match, C and D are invalid syntax or cause errors.
❓ locator
advanced2:00remaining
Best locator strategy for a button with dynamic ID
You want to locate a button with a dynamic ID that changes every page load but has a stable class 'submit-btn' and visible text 'Submit'. Which locator is best for Selenium?
Attempts:
2 left
💡 Hint
Use XPath to combine text and class attributes for stable selection
✗ Incorrect
Option C uses XPath to find a button element containing the text 'Submit' and class 'submit-btn', which is stable despite dynamic IDs. Option C uses a dynamic ID which changes, B only uses class which may match multiple elements, D uses name which may not exist.
🔧 Debug
advanced2:30remaining
Identify the cause of flaky Selenium test failure
This pytest Selenium test intermittently fails with NoSuchElementException. What is the most likely cause?
Selenium Python
def test_login(driver): driver.get('https://mysite.com/login') driver.find_element('id', 'username').send_keys('user') driver.find_element('id', 'password').send_keys('pass') driver.find_element('id', 'submit').click() assert 'Dashboard' in driver.title
Attempts:
2 left
💡 Hint
Web pages may take time to load elements; Selenium needs waits
✗ Incorrect
NoSuchElementException usually means Selenium tried to find an element before it appeared. Adding explicit waits or expected conditions solves this. Other options do not explain intermittent failure.
❓ framework
expert2:00remaining
pytest Selenium parallel test execution setup
Which pytest command correctly runs Selenium tests in parallel across 4 browser instances using pytest-xdist?
Attempts:
2 left
💡 Hint
pytest-xdist uses -n option to specify number of parallel workers
✗ Incorrect
Option A uses pytest-xdist's -n 4 to run tests in 4 parallel processes. The --browser option is commonly used in Selenium pytest setups to specify browser. Other options use invalid flags.