Bird
0
0

What will happen if you run this pytest test?

medium📝 Predict Output Q5 of 15
Selenium Python - Test Framework Integration (pytest)
What will happen if you run this pytest test?
import pytest
from selenium import webdriver

@pytest.fixture
 def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.close()

def test_url(driver):
    driver.get('https://example.com')
    assert driver.current_url == 'https://example.com/'
ATest passes but browser remains open
BTest fails because driver.close() does not quit browser properly
CTest raises an exception due to missing driver.quit()
DTest passes and browser closes after test
Step-by-Step Solution
Solution:
  1. Step 1: Understand driver.close() vs driver.quit()

    driver.close() closes current window but if only one window, browser closes too.
  2. Step 2: Analyze test behavior

    Test asserts current URL correctly and driver.close() closes browser after test.
  3. Final Answer:

    Test passes and browser closes after test -> Option D
  4. Quick Check:

    driver.close() closes browser if single window [OK]
Quick Trick: driver.close() closes window; driver.quit() quits browser [OK]
Common Mistakes:
  • Confusing driver.close() with driver.quit()
  • Assuming test fails without driver.quit()
  • Thinking browser stays open after driver.close()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes