0
0
Testing Fundamentalstesting~15 mins

Boundary value analysis in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Test input field with boundary values
Preconditions (3)
Step 1: Enter 0 in the input field and submit
Step 2: Verify the error message 'Input out of range' is displayed
Step 3: Enter 1 in the input field and submit
Step 4: Verify the success message 'Input accepted' is displayed
Step 5: Enter 100 in the input field and submit
Step 6: Verify the success message 'Input accepted' is displayed
Step 7: Enter 101 in the input field and submit
Step 8: Verify the error message 'Input out of range' is displayed
✅ Expected Result: The application correctly accepts inputs 1 and 100 and rejects inputs 0 and 101 with appropriate messages
Automation Requirements - Selenium with Python
Assertions Needed:
Verify error message 'Input out of range' appears for invalid inputs
Verify success message 'Input accepted' appears for valid inputs
Best Practices:
Use explicit waits to wait for messages to appear
Use clear and maintainable locators (e.g., By.ID or By.CSS_SELECTOR)
Separate test data from test logic
Use assertions that clearly check the message text
Automated Solution
Testing Fundamentals
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.

Common Mistakes - 4 Pitfalls
Using hardcoded sleep instead of explicit waits
Using brittle XPath locators that depend on full element paths
Not clearing the input field before entering new values
Not verifying the exact message text
Bonus Challenge

Now add data-driven testing with 3 different valid inputs and 3 invalid inputs using a test data structure

Show Hint