Bird
0
0

Which of the following is the correct way to define a pytest fixture for browser setup and teardown using yield?

easy📝 Syntax Q12 of 15
Selenium Python - Test Framework Integration (pytest)
Which of the following is the correct way to define a pytest fixture for browser setup and teardown using yield?
Adef browser(): driver = webdriver.Chrome() yield driver driver.quit()
Bdef browser(): driver = webdriver.Chrome() driver.quit() yield driver
Cdef browser(): yield webdriver.Chrome() driver.quit()
Ddef browser(): driver = webdriver.Chrome() driver.close() yield driver
Step-by-Step Solution
Solution:
  1. Step 1: Understand yield usage in fixtures

    Yield separates setup (before yield) and teardown (after yield).
  2. Step 2: Check correct order

    Setup: create driver; yield it; teardown: quit driver.
  3. Final Answer:

    def browser(): driver = webdriver.Chrome() yield driver driver.quit() -> Option A
  4. Quick Check:

    Setup before yield, teardown after yield [OK]
Quick Trick: Setup before yield, teardown after yield in fixture [OK]
Common Mistakes:
  • Calling quit before yield
  • Using driver.close() instead of driver.quit() for teardown
  • Yielding before creating driver

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes