Network condition testing in Testing Fundamentals - Build an Automation Script
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time # Setup Chrome driver with DevTools Protocol options = webdriver.ChromeOptions() service = Service() driver = webdriver.Chrome(service=service, options=options) try: # Enable network throttling to simulate slow 3G driver.execute_cdp_cmd('Network.enable', {}) driver.execute_cdp_cmd('Network.emulateNetworkConditions', { 'offline': False, 'latency': 200, # 200 ms latency 'downloadThroughput': 500 * 1024 / 8, # 500 kbps 'uploadThroughput': 500 * 1024 / 8 # 500 kbps }) start_time = time.time() driver.get('https://example.com') # Replace with actual app URL # Wait for main element to load WebDriverWait(driver, 30).until( EC.presence_of_element_located((By.ID, 'main-content')) ) load_time = time.time() - start_time # Assert page load time under 15 seconds for slow network assert load_time < 15, f"Page load took too long: {load_time} seconds" # Fill and submit form input_field = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, 'input-name')) ) input_field.send_keys('Test User') submit_button = driver.find_element(By.ID, 'submit-btn') submit_button.click() # Wait for success message success_msg = WebDriverWait(driver, 15).until( EC.visibility_of_element_located((By.ID, 'success-message')) ) assert 'success' in success_msg.text.lower(), "Success message not displayed" finally: driver.quit()
This script uses Selenium WebDriver with Chrome DevTools Protocol to simulate a slow 3G network by setting latency and throughput limits.
We start by enabling network throttling, then load the application page and measure the load time.
We assert that the page loads within 15 seconds, which is reasonable for slow networks.
Next, we fill a form field and submit it, then wait for a success message to confirm the form submission worked.
Explicit waits ensure the script waits for elements to be ready before interacting, avoiding flaky tests.
Finally, the driver quits to close the browser cleanly.
Now add data-driven testing with 3 different network speeds: slow 3G, fast 3G, and 4G
Practice
network condition testing in software testing?Solution
Step 1: Understand network condition testing
Network condition testing focuses on how software performs with various internet speeds and qualities.Step 2: Compare options to the definition
Only To check how an app behaves under different internet speeds and qualities matches this purpose; others focus on unrelated testing areas.Final Answer:
To check how an app behaves under different internet speeds and qualities -> Option AQuick Check:
Network condition testing = Check app behavior on different networks [OK]
- Confusing network testing with UI testing
- Thinking it only tests database or installation
Solution
Step 1: Identify how to simulate slow network
Slow network simulation requires reducing speed and adding latency (delay).Step 2: Evaluate options
Set network speed to 3 Mbps and add 200 ms latency sets a low speed and adds latency, correctly simulating slow network. Others do not simulate slow network.Final Answer:
Set network speed to 3 Mbps and add 200 ms latency -> Option AQuick Check:
Slow network = low speed + latency [OK]
- Choosing high speed as slow network
- Ignoring latency in simulation
simulateNetwork(10, 150)?Solution
Step 1: Check speed condition
Speed is 10 Mbps, which is not less than 5, so skip first condition.Step 2: Check latency condition
Latency is 150 ms, which is greater than 100, so return "High Latency".Final Answer:
"High Latency" -> Option BQuick Check:
Latency > 100 triggers "High Latency" [OK]
- Choosing "Slow Network" ignoring speed value
- Assuming good network despite high latency
networkSpeed = 2
latency = 50
if (networkSpeed > 5) {
print("Fast Network")
} else if (latency > 100) {
print("High Latency")
} else {
print("Slow Network")
}
What is the output and is there any logical error?Solution
Step 1: Evaluate conditions with given values
networkSpeed=2 (not >5), latency=50 (not >100), so else block runs printing "Slow Network".Step 2: Check for logical errors
Conditions correctly cover cases; no error in logic.Final Answer:
Output: "Slow Network"; No logical error -> Option DQuick Check:
Speed low and latency low = "Slow Network" [OK]
- Assuming latency triggers "High Latency" incorrectly
- Thinking there is a logical error when none exists
Solution
Step 1: Understand unstable network testing
Unstable network means changing speeds during use, so simulation must alternate speeds.Step 2: Evaluate options for best fit
Use a network simulation tool to alternate speeds during the test uses a tool to alternate speeds, matching unstable network testing. Others ignore instability.Final Answer:
Use a network simulation tool to alternate speeds during the test -> Option CQuick Check:
Unstable network = alternating speeds [OK]
- Testing only stable networks for unstable scenarios
- Ignoring network speed in testing
Ready to prove it?
Pass the test and this pattern moves unknown
