Bird
0
0

What is wrong with this fixture code?

medium📝 Debug Q7 of 15
Selenium Python - Test Framework Integration (pytest)
What is wrong with this fixture code?
@pytest.fixture
def browser():
    driver = webdriver.Chrome()
    yield driver
    driver.close()
Adriver.close() causes syntax error in fixture.
Bdriver.close() closes only the current window, not the entire browser session.
Cdriver.close() should be called before yield.
Ddriver.close() is not a valid WebDriver method.
Step-by-Step Solution
Solution:
  1. Step 1: Understand difference between close() and quit()

    driver.close() closes the current browser window, but driver.quit() closes the entire browser session.
  2. Step 2: Identify proper teardown method

    For full cleanup, driver.quit() should be used in teardown, not driver.close().
  3. Final Answer:

    driver.close() closes only the current window, not the entire browser session. -> Option B
  4. Quick Check:

    Use quit() for full browser shutdown [OK]
Quick Trick: Use driver.quit() to close browser fully [OK]
Common Mistakes:
  • Calling close() instead of quit() for teardown
  • Calling close() before yield
  • Assuming close() causes syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes