Bird
0
0

What is wrong with this pytest fixture for Selenium?

medium📝 Debug Q7 of 15
Selenium Python - Test Framework Integration (pytest)
What is wrong with this pytest fixture for Selenium?
@pytest.fixture
def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.close()
    driver.quit()
AMissing import statement for webdriver
BCalling driver.close() before driver.quit() may cause errors
CYield must be replaced with return
DFixture must have scope='session'
Step-by-Step Solution
Solution:
  1. Step 1: Understand driver.close() and driver.quit()

    driver.close() closes current window; driver.quit() closes all windows and ends session.
  2. Step 2: Analyze order of calls

    Calling close() then quit() can cause errors if close() closes the only window before quit().
  3. Final Answer:

    Calling driver.close() before driver.quit() may cause errors -> Option B
  4. Quick Check:

    Call quit() directly to avoid errors [OK]
Quick Trick: Use driver.quit() alone for cleanup [OK]
Common Mistakes:
  • Calling close() before quit()
  • Confusing yield with return
  • Assuming scope is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes