Bird
0
0

Given the following pytest test code, what will be the output when running the test?

medium📝 Predict Output Q13 of 15
Selenium Python - Test Framework Integration (pytest)
Given the following pytest test code, what will be the output when running the test?
import pytest
from selenium import webdriver

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


def test_google_title(browser):
    browser.get('https://www.google.com')
    assert 'Google' in browser.title
ATest passes if the browser opens Google and title contains 'Google'
BTest fails because browser.title is empty
CSyntaxError due to missing import
DRuntimeError because driver.quit() is called too early
Step-by-Step Solution
Solution:
  1. Step 1: Analyze fixture and test function

    The fixture opens Chrome, yields the driver, and quits after test. The test navigates to Google and asserts title contains 'Google'.
  2. Step 2: Understand expected behavior

    Since Google page title contains 'Google', the assertion passes and test completes successfully.
  3. Final Answer:

    Test passes if the browser opens Google and title contains 'Google' -> Option A
  4. Quick Check:

    Title contains 'Google' means pass = B [OK]
Quick Trick: Check page title contains expected text for pass [OK]
Common Mistakes:
  • Assuming title is empty before page load
  • Thinking driver.quit() runs before test
  • Missing import statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes