Bird
0
0

How can you modify a pytest Selenium fixture to accept a browser name parameter (e.g., 'chrome' or 'firefox') from the command line?

hard📝 Application Q9 of 15
Selenium Python - Test Framework Integration (pytest)
How can you modify a pytest Selenium fixture to accept a browser name parameter (e.g., 'chrome' or 'firefox') from the command line?
AUse pytest_addoption to add a command line option and access it in the fixture via request.config
BHardcode browser name inside the fixture
CUse environment variables only, no pytest support
DPass browser name as a test function argument
Step-by-Step Solution
Solution:
  1. Step 1: Understand pytest command line options

    pytest_addoption hook allows adding custom CLI options accessible in fixtures.
  2. Step 2: Access option in fixture

    Fixture can get browser name from request.config.getoption() to initialize correct driver.
  3. Final Answer:

    Use pytest_addoption to add a command line option and access it in the fixture via request.config -> Option A
  4. Quick Check:

    pytest_addoption enables CLI parameters [OK]
Quick Trick: Use pytest_addoption and request.config in fixtures [OK]
Common Mistakes:
  • Hardcoding browser disables flexibility
  • Ignoring pytest CLI options
  • Passing browser name as test arg is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes