Test Overview
This test opens a browser, navigates to a website, captures network logs during the page load, and verifies that the network log contains expected entries.
This test opens a browser, navigates to a website, captures network logs during the page load, and verifies that the network log contains expected entries.
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options import json import time # Setup Chrome options to enable performance logging chrome_options = Options() chrome_options.set_capability('goog:loggingPrefs', {'performance': 'ALL'}) # Initialize WebDriver service = Service() driver = webdriver.Chrome(service=service, options=chrome_options) try: # Navigate to example website driver.get('https://example.com') time.sleep(3) # Wait for network activity # Capture performance logs logs = driver.get_log('performance') # Filter network request logs network_logs = [] for entry in logs: message = json.loads(entry['message'])['message'] if message['method'] == 'Network.requestWillBeSent': network_logs.append(message['params']['request']['url']) # Assert that the main page URL is in the network logs assert 'https://example.com/' in network_logs finally: driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Initialize Chrome WebDriver with performance logging enabled | Chrome browser instance is ready with logging preferences set | - | PASS |
| 2 | Navigate to 'https://example.com' | Browser loads the example.com homepage | - | PASS |
| 3 | Wait 3 seconds to allow network requests to complete | Page and network activity stabilize | - | PASS |
| 4 | Retrieve performance logs from the browser | Collected raw performance log entries | - | PASS |
| 5 | Filter logs to extract URLs from 'Network.requestWillBeSent' events | List of requested URLs during page load is prepared | - | PASS |
| 6 | Assert that 'https://example.com/' is in the network logs | Verified that main page URL was requested | assert 'https://example.com/' in network_logs | PASS |
| 7 | Close the browser | Browser instance closed | - | PASS |