Boundary value analysis in Testing Fundamentals - Build an Automation Script
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 import unittest class BoundaryValueTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://example.com/input-form') # Replace with actual URL self.wait = WebDriverWait(self.driver, 10) def enter_value_and_submit(self, value): input_field = self.wait.until(EC.presence_of_element_located((By.ID, 'number-input'))) input_field.clear() input_field.send_keys(str(value)) submit_button = self.driver.find_element(By.ID, 'submit-btn') submit_button.click() def get_message_text(self): message = self.wait.until(EC.visibility_of_element_located((By.ID, 'message'))) return message.text def test_boundary_values(self): test_cases = [ (0, 'Input out of range'), (1, 'Input accepted'), (100, 'Input accepted'), (101, 'Input out of range') ] for value, expected_message in test_cases: with self.subTest(value=value): self.enter_value_and_submit(value) actual_message = self.get_message_text() self.assertEqual(actual_message, expected_message, f'Failed for input {value}') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
This test script uses Selenium with Python's unittest framework to automate boundary value analysis.
setUp: Opens the browser and navigates to the input form page.
enter_value_and_submit: Enters a value into the input field and clicks submit.
get_message_text: Waits for the message element to appear and returns its text.
test_boundary_values: Runs tests for four boundary values (0, 1, 100, 101) checking the displayed message matches expected.
tearDown: Closes the browser after tests.
Explicit waits ensure the test waits for elements and messages properly. Using subTest helps identify which input fails if any.
Now add data-driven testing with 3 different valid inputs and 3 invalid inputs using a test data structure
Practice
Boundary Value Analysis in software testing?Solution
Step 1: Understand boundary value analysis purpose
Boundary value analysis focuses on testing the edges or limits of input ranges where errors often occur.Step 2: Compare options with definition
Only To test inputs at the edges of input ranges correctly describes testing inputs at the edges of input ranges.Final Answer:
To test inputs at the edges of input ranges -> Option BQuick Check:
Boundary value analysis = test edges [OK]
- Confusing boundary testing with performance testing
- Testing only middle values instead of edges
- Ignoring values just outside the boundaries
Solution
Step 1: Identify boundary values for range 1 to 10
Boundaries are minimum (1) and maximum (10). Values just outside are 0 and 11.Step 2: Check options for boundary and just outside values
0, 1, 10, 11 includes 0 (just below min), 1 (min), 10 (max), and 11 (just above max), which is correct for boundary testing.Final Answer:
0, 1, 10, 11 -> Option DQuick Check:
Include min, max, and just outside values [OK]
- Testing only valid values inside the range
- Ignoring values just outside the boundaries
- Choosing random values without boundary focus
Solution
Step 1: Identify boundary values and just outside values
Boundaries are 5 (min) and 15 (max). Just outside are 4 and 16.Step 2: Check which input is not a boundary or just outside value
Inputs 4, 5, and 15 are boundary or just outside values. 10 is a normal middle value, not a boundary test case.Final Answer:
10 -> Option AQuick Check:
Boundary tests exclude middle values like 10 [OK]
- Including middle values as boundary tests
- Ignoring values just outside boundaries
- Confusing valid inputs with boundary inputs
Solution
Step 1: Understand boundary test inputs and expected behavior
Inputs 9 and 21 are just outside the valid range 10 to 20, so failure on 21 is expected.Step 2: Analyze test failure reason
Since 21 is invalid input, failure means software correctly rejects it. So test failure is expected, not a bug.Final Answer:
21 is outside the valid input range and should fail -> Option CQuick Check:
Outside boundary inputs should cause failure [OK]
- Thinking failure on invalid input is a bug
- Not testing values just outside boundaries
- Assuming all test inputs must pass
Solution
Step 1: Identify boundary and just outside values for age 18 to 60
Boundaries are 18 (min) and 60 (max). Just outside are 17 (below min) and 61 (above max).Step 2: Check which option includes all boundaries and just outside values
17, 18, 60, 61 includes 17, 18, 60, and 61, covering all required boundary and just outside values.Final Answer:
17, 18, 60, 61 -> Option AQuick Check:
Test min, max, and just outside values for full coverage [OK]
- Missing just outside boundary values
- Testing only valid inputs inside range
- Confusing boundary values with random inputs
Ready to prove it?
Pass the test and this pattern moves unknown
