Bird
0
0

In a CI pipeline, you want to run Selenium tests with Chrome in headless mode but also capture screenshots on failure. Which approach is best?

hard📝 Application Q9 of 15
Selenium Python - CI/CD Integration
In a CI pipeline, you want to run Selenium tests with Chrome in headless mode but also capture screenshots on failure. Which approach is best?
ARun Chrome in normal mode and manually take screenshots
BUse headless Chrome with Selenium's get_screenshot_as_file() in exception handling
CDisable screenshots and rely on logs only
DUse Firefox instead because Chrome can't take screenshots headlessly
Step-by-Step Solution
Solution:
  1. Step 1: Confirm headless Chrome supports screenshots

    Headless Chrome can capture screenshots using Selenium's methods.
  2. Step 2: Implement screenshot capture in exception handling

    Using get_screenshot_as_file() inside try-except blocks captures failures automatically.
  3. Final Answer:

    Use headless Chrome with Selenium's get_screenshot_as_file() in exception handling -> Option B
  4. Quick Check:

    Headless screenshots with exception handling = B [OK]
Quick Trick: Capture screenshots on failure using Selenium's method in headless mode [OK]
Common Mistakes:
  • Thinking headless can't capture screenshots
  • Ignoring exception handling

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes