0
0
Selenium Pythontesting~10 mins

Full page screenshot in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a webpage and captures a full page screenshot. It verifies that the screenshot file is created successfully.

Test Code - Selenium
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import os
import time

def test_full_page_screenshot():
    options = Options()
    options.add_argument('--headless=new')
    service = Service()
    driver = webdriver.Chrome(service=service, options=options)
    try:
        driver.get('https://example.com')
        time.sleep(2)  # Wait for page to load fully
        screenshot_path = 'full_page_screenshot.png'
        # Selenium 4.1+ supports full page screenshot for Chrome
        driver.get_full_page_screenshot_as_file(screenshot_path)
        assert os.path.exists(screenshot_path), 'Screenshot file was not created.'
    finally:
        driver.quit()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test startsTest environment initialized, ChromeDriver ready-PASS
2Browser opens Chrome in headless modeChrome browser instance running without UI-PASS
3Navigates to 'https://example.com'Example.com homepage loaded fully-PASS
4Waits 2 seconds for full page loadPage content fully rendered-PASS
5Captures full page screenshot and saves as 'full_page_screenshot.png'Screenshot file created in test folderCheck if 'full_page_screenshot.png' file existsPASS
6Closes browser and ends testBrowser closed, resources freed-PASS
Failure Scenario
Failing Condition: Screenshot file is not created due to permission issues or driver incompatibility
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after taking the screenshot?
AThat the browser is visible
BThat the page title is correct
CThat the screenshot file exists on disk
DThat the URL contains 'example'
Key Result
Always verify that your test artifacts, like screenshots, are actually created to ensure your test is meaningful and reliable.