Bird
Raised Fist0
Testing Fundamentalstesting~10 mins

Network condition testing in Testing Fundamentals - Test Execution Trace

Choose your learning style10 modes available
Test Overview

This test checks how a web application behaves when the network is slow or disconnected. It verifies that the app shows a loading message during slow network and an error message when offline.

Test Code - Selenium
Testing Fundamentals
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class NetworkConditionTest(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com')

    def test_slow_network_loading(self):
        # Simulate slow network using Chrome DevTools Protocol
        self.driver.execute_cdp_cmd('Network.enable', {})
        self.driver.execute_cdp_cmd('Network.emulateNetworkConditions', {
            'offline': False,
            'latency': 2000,  # 2 seconds delay
            'downloadThroughput': 500 * 1024 / 8,  # 500 kbps
            'uploadThroughput': 500 * 1024 / 8
        })

        self.driver.refresh()

        # Wait for loading message
        loading = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located((By.ID, 'loading-message'))
        )
        self.assertEqual(loading.text, 'Loading...')

    def test_offline_error_message(self):
        # Simulate offline mode
        self.driver.execute_cdp_cmd('Network.enable', {})
        self.driver.execute_cdp_cmd('Network.emulateNetworkConditions', {
            'offline': True,
            'latency': 0,
            'downloadThroughput': 0,
            'uploadThroughput': 0
        })

        self.driver.refresh()

        # Wait for error message
        error = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located((By.ID, 'error-message'))
        )
        self.assertEqual(error.text, 'No internet connection')

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser opened at https://example.com—PASS
2Enable network emulation and set slow network conditionsNetwork throttling set: 2s latency, 500 kbps throughput—PASS
3Refresh the page to apply network conditionsPage reloads with slow network—PASS
4Wait for loading message element with ID 'loading-message'Loading message visible on pageVerify loading message text is 'Loading...'PASS
5Enable network emulation and set offline modeNetwork set to offline—PASS
6Refresh the page to apply offline conditionPage reloads with no network—PASS
7Wait for error message element with ID 'error-message'Error message visible on pageVerify error message text is 'No internet connection'PASS
8Close browser and end testBrowser closed—PASS
Failure Scenario
Failing Condition: The network emulation commands fail or the expected elements do not appear within timeout
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify when the network is slow?
AThe page loads instantly
BThe page shows an error message
CThe page shows a loading message
DThe page redirects to another site
Key Result
Using network emulation in tests helps verify app behavior under real-world slow or offline conditions, improving user experience reliability.

Practice

(1/5)
1. What is the main purpose of network condition testing in software testing?
easy
A. To check how an app behaves under different internet speeds and qualities
B. To test the app's user interface design
C. To verify database connections only
D. To check the app's installation process

Solution

  1. Step 1: Understand network condition testing

    Network condition testing focuses on how software performs with various internet speeds and qualities.
  2. 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.
  3. Final Answer:

    To check how an app behaves under different internet speeds and qualities -> Option A
  4. Quick Check:

    Network condition testing = Check app behavior on different networks [OK]
Hint: Focus on internet speed and quality effects on app [OK]
Common Mistakes:
  • Confusing network testing with UI testing
  • Thinking it only tests database or installation
2. Which of the following is the correct way to simulate a slow network in a testing tool?
easy
A. Set network speed to 3 Mbps and add 200 ms latency
B. Set network speed to 100 Mbps with 0 ms latency
C. Disable network throttling completely
D. Increase CPU usage to 90%

Solution

  1. Step 1: Identify how to simulate slow network

    Slow network simulation requires reducing speed and adding latency (delay).
  2. 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.
  3. Final Answer:

    Set network speed to 3 Mbps and add 200 ms latency -> Option A
  4. Quick Check:

    Slow network = low speed + latency [OK]
Hint: Slow network means low speed plus added delay [OK]
Common Mistakes:
  • Choosing high speed as slow network
  • Ignoring latency in simulation
3. Consider this pseudocode simulating network conditions: <pre>simulateNetwork(speedMbps, latencyMs) { if (speedMbps < 5) return "Slow Network"; else if (latencyMs > 100) return "High Latency"; else return "Good Network"; } What will be the output of simulateNetwork(10, 150)?
medium
A. "Slow Network"
B. "High Latency"
C. "Good Network"
D. Runtime Error

Solution

  1. Step 1: Check speed condition

    Speed is 10 Mbps, which is not less than 5, so skip first condition.
  2. Step 2: Check latency condition

    Latency is 150 ms, which is greater than 100, so return "High Latency".
  3. Final Answer:

    "High Latency" -> Option B
  4. Quick Check:

    Latency > 100 triggers "High Latency" [OK]
Hint: Check conditions in order, latency > 100 returns "High Latency" [OK]
Common Mistakes:
  • Choosing "Slow Network" ignoring speed value
  • Assuming good network despite high latency
4. You have this test code snippet to simulate network conditions:
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?
medium
A. Output: "Fast Network"; Logical error in conditions
B. Output: "Slow Network"; Logical error in conditions
C. Output: "High Latency"; Logical error in conditions
D. Output: "Slow Network"; No logical error

Solution

  1. Step 1: Evaluate conditions with given values

    networkSpeed=2 (not >5), latency=50 (not >100), so else block runs printing "Slow Network".
  2. Step 2: Check for logical errors

    Conditions correctly cover cases; no error in logic.
  3. Final Answer:

    Output: "Slow Network"; No logical error -> Option D
  4. Quick Check:

    Speed low and latency low = "Slow Network" [OK]
Hint: Check conditions with given values carefully [OK]
Common Mistakes:
  • Assuming latency triggers "High Latency" incorrectly
  • Thinking there is a logical error when none exists
5. You want to test an app's behavior under unstable network conditions that randomly switch between fast and slow speeds. Which approach is best?
hard
A. Test only on a stable slow network
B. Test only on a stable fast network
C. Use a network simulation tool to alternate speeds during the test
D. Ignore network speed and focus on UI testing

Solution

  1. Step 1: Understand unstable network testing

    Unstable network means changing speeds during use, so simulation must alternate speeds.
  2. 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.
  3. Final Answer:

    Use a network simulation tool to alternate speeds during the test -> Option C
  4. Quick Check:

    Unstable network = alternating speeds [OK]
Hint: Simulate speed changes to mimic unstable network [OK]
Common Mistakes:
  • Testing only stable networks for unstable scenarios
  • Ignoring network speed in testing
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard