0
0
Selenium Pythontesting~10 mins

Window size control in Selenium Python - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test opens a browser, sets the window size to 1024x768 pixels, and verifies that the window size is correctly applied.

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

# Initialize Chrome WebDriver
service = Service()
driver = webdriver.Chrome(service=service)

try:
    # Open a website
    driver.get('https://example.com')

    # Set window size to 1024x768
    driver.set_window_size(1024, 768)

    # Get current window size
    size = driver.get_window_size()

    # Assert window size is as expected
    assert size['width'] == 1024 and size['height'] == 768, f"Window size is {size}, expected 1024x768"

finally:
    driver.quit()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Initialize Chrome WebDriverBrowser is starting but not yet opened any page-PASS
2Open the URL 'https://example.com'Browser displays the Example Domain homepage-PASS
3Set browser window size to width=1024 and height=768Browser window is resized to 1024x768 pixels-PASS
4Retrieve current window sizeBrowser window size info is fetchedCheck if width == 1024 and height == 768PASS
5Assert that window size matches 1024x768Window size is confirmed as 1024x768Assertion passes if size matches expected valuesPASS
6Close the browserBrowser is closed and WebDriver session ends-PASS
Failure Scenario
Failing Condition: Window size after setting does not match 1024x768
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after setting the window size?
AThat the page title contains 'Example Domain'
BThat the browser navigated to the correct URL
CThat the browser window size is exactly 1024x768 pixels
DThat the browser window is maximized
Key Result
Always verify that window size changes are applied by retrieving the size after setting it, to ensure your test environment matches expected conditions.