Bird
0
0

What is wrong with this fixture code for browser setup and teardown?

medium📝 Debug Q14 of 15
Selenium Python - Test Framework Integration (pytest)
What is wrong with this fixture code for browser setup and teardown?
@pytest.fixture
def browser():
    driver = webdriver.Chrome()
    driver.quit()
    yield driver
AMissing import statement for webdriver
BCalling driver.quit() before yield closes browser too early
CYield should be inside a try-except block
DFixture should return driver instead of yield
Step-by-Step Solution
Solution:
  1. Step 1: Analyze order of operations

    driver.quit() is called before yield, so browser closes before test uses it.
  2. Step 2: Understand yield role

    Yield should come before teardown to keep browser open during test.
  3. Final Answer:

    Calling driver.quit() before yield closes browser too early -> Option B
  4. Quick Check:

    Teardown must be after yield [OK]
Quick Trick: Teardown code must be after yield in fixture [OK]
Common Mistakes:
  • Calling quit before yield
  • Confusing yield with return
  • Ignoring fixture import requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes