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.