Network log capture is the process of recording all network requests and responses made by the browser during a test. It helps testers see what data is sent and received, like a phone call record for the browser.
Click to reveal answer
intermediate
Which Selenium feature allows capturing network logs in Python?
Using Selenium with Chrome DevTools Protocol (CDP) allows capturing network logs. You enable performance logging in Chrome options and then access logs via Selenium's driver.get_log('performance').
Click to reveal answer
beginner
Why is capturing network logs useful in testing?
It helps verify if the right API calls are made, check response data, find slow requests, and detect errors invisible on the page. Like checking the mailman’s delivery to ensure messages arrived correctly.
Click to reveal answer
intermediate
How do you enable performance logging in ChromeDriver for Selenium Python?
You create ChromeOptions, add the experimental option 'perfLoggingPrefs' with {'enableNetwork': True}, and set 'loggingPrefs' in capabilities to enable performance logging. Then pass these options and capabilities to ChromeDriver.
Click to reveal answer
beginner
What kind of information can you find in network logs captured during Selenium tests?
You can find request URLs, HTTP methods, status codes, headers, request and response bodies, and timing details. This helps understand what data the browser exchanged with servers.
Click to reveal answer
What is the main purpose of capturing network logs in Selenium tests?
ATo change the browser's UI
BTo speed up the test execution
CTo see all network requests and responses during the test
DTo write test cases automatically
✗ Incorrect
Network logs show all network activity, helping testers verify data exchange.
Which Selenium driver supports capturing network logs via Chrome DevTools Protocol?
AFirefoxDriver
BChromeDriver
CEdgeDriver
DSafariDriver
✗ Incorrect
ChromeDriver supports CDP which allows network log capture.
How do you access network logs in Selenium Python after enabling performance logging?
Adriver.get_log('performance')
Bdriver.get_log('network')
Cdriver.get_network_logs()
Ddriver.get_logs()
✗ Incorrect
Performance logs include network events and are accessed with 'performance'.
Which of these is NOT typically found in network logs?
AHTTP status codes
BRequest URLs
CRequest and response headers
DBrowser UI layout
✗ Incorrect
Network logs do not include browser UI layout information.
Why might a tester want to check network logs during a test?
ATo verify API calls and responses
BTo change the test script automatically
CTo speed up page loading
DTo change browser settings
✗ Incorrect
Checking API calls and responses helps ensure correct backend communication.
Explain how to enable and capture network logs in Selenium using Python and ChromeDriver.
Think about Chrome DevTools Protocol and performance logs.
You got /4 concepts.
Describe why network log capture is important in software testing and what information it provides.
Consider how network logs help understand backend communication.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of capturing network logs in Selenium tests?
easy
A. To see the communication between browser and server during tests
B. To speed up the test execution time
C. To change the browser's UI elements
D. To generate random test data automatically
Solution
Step 1: Understand network logs in Selenium
Network logs capture the details of requests and responses between the browser and server during test execution.
Step 2: Identify the main purpose
This helps testers verify if the correct URLs are called and if responses are successful.
Final Answer:
To see the communication between browser and server during tests -> Option A
Quick Check:
Network logs show browser-server communication [OK]
Hint: Network logs = browser-server communication details [OK]
Common Mistakes:
Thinking network logs speed up tests
Confusing UI changes with network logs
Assuming network logs generate test data
2. Which Chrome option enables performance logging to capture network events in Selenium?
easy
A. "args": ["--disable-extensions"]
B. "goog:loggingPrefs": {"performance": "ALL"}
C. "prefs": {"download.default_directory": "/tmp"}
D. "chromeOptions": {"headless": true}
Solution
Step 1: Identify the correct Chrome option for logging
Performance logging is enabled by setting "goog:loggingPrefs" with "performance" set to "ALL".
Step 2: Understand other options
Other options like headless mode or disabling extensions do not enable network log capture.
Final Answer:
"goog:loggingPrefs": {"performance": "ALL"} -> Option B
Quick Check:
Enable performance logs with goog:loggingPrefs [OK]
Hint: Use goog:loggingPrefs with performance ALL to capture network logs [OK]
Common Mistakes:
Confusing headless mode with logging
Using download preferences for network logs
Disabling extensions instead of enabling logs
3. Given this code snippet, what will be printed?
logs = driver.get_log('performance')
for entry in logs:
message = json.loads(entry['message'])['message']
if message['method'] == 'Network.responseReceived':
print(message['params']['response']['url'])
medium
A. All browser console error messages
B. Only URLs of failed network requests
C. All URLs of network responses received during the test
D. List of all clickable elements on the page
Solution
Step 1: Understand the log parsing code
The code reads performance logs, filters for 'Network.responseReceived' events, and prints the response URLs.
Step 2: Identify what is printed
It prints all URLs for network responses received, regardless of success or failure.
Final Answer:
All URLs of network responses received during the test -> Option C
Quick Check:
Code prints URLs from Network.responseReceived events [OK]
Hint: Network.responseReceived logs contain all response URLs [OK]
Common Mistakes:
Assuming only failed URLs are printed
Confusing network logs with console errors
Thinking it lists page elements
4. What is wrong with this code snippet for capturing network logs?