Test Overview
This test opens a webpage and captures a full page screenshot. It verifies that the screenshot file is created successfully.
This test opens a webpage and captures a full page screenshot. It verifies that the screenshot file is created successfully.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test environment initialized, ChromeDriver ready | — | PASS |
| 2 | Browser opens Chrome in headless mode | Chrome browser instance running without UI | — | PASS |
| 3 | Navigates to 'https://example.com' | Example.com homepage loaded fully | — | PASS |
| 4 | Waits 2 seconds for full page load | Page content fully rendered | — | PASS |
| 5 | Captures full page screenshot and saves as 'full_page_screenshot.png' | Screenshot file created in test folder | Check if 'full_page_screenshot.png' file exists | PASS |
| 6 | Closes browser and ends test | Browser closed, resources freed | — | PASS |
save_full_page_screenshot. The standard method to save a screenshot is get_screenshot_as_file, which captures the visible viewport.save_full_page_screenshot is not a standard Selenium method. driver.save_screenshot('file.png') saves visible viewport screenshot. driver.take_full_screenshot('file.png') is not a valid method.driver.get('https://example.com')
driver.save_full_page_screenshot('page.png')
print('Screenshot saved')save_full_page_screenshot is not a valid Selenium WebDriver method and will cause a SyntaxError or AttributeError.driver.get('https://example.com')
driver.save_screenshot('screen.png')
What is the likely cause?Pass the test and this pattern moves unknown