Test Overview
This test opens a browser, sets the window size to 1024x768 pixels, and verifies that the window size is correctly applied.
This test opens a browser, sets the window size to 1024x768 pixels, and verifies that the window size is correctly applied.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Initialize Chrome WebDriver | Browser is starting but not yet opened any page | — | PASS |
| 2 | Open the URL 'https://example.com' | Browser displays the Example Domain homepage | — | PASS |
| 3 | Set browser window size to width=1024 and height=768 | Browser window is resized to 1024x768 pixels | — | PASS |
| 4 | Retrieve current window size | Browser window size info is fetched | Check if width == 1024 and height == 768 | PASS |
| 5 | Assert that window size matches 1024x768 | Window size is confirmed as 1024x768 | Assertion passes if size matches expected values | PASS |
| 6 | Close the browser | Browser is closed and WebDriver session ends | — | PASS |
set_window_size(width, height) do in a test script?set_window_size(width, height) is designed to set the browser window to a specific size.maximize_window(), close(), or refresh().set_window_size(width, height) with underscore and lowercase.driver.set_window_size(1024, 768).driver.set_window_size(800, 600) size = driver.get_window_size() print(size)
get_window_size() returns a dictionary with keys 'width' and 'height' reflecting the current window size.driver.set_window_size(1024)
set_window_size requires two parameters: width and height.set_window_size(w, h).setWindowSize (incorrect for Python Selenium). sizes = [(320, 480), (768, 1024), (1920, 1080)]
for size in sizes:
driver.set_window_size(size) loops but passes tuples directly (TypeError, expects two arguments).Pass the test and this pattern moves unknown