Test Overview
This test opens a web page with a date picker, selects a specific date, and verifies the date is correctly set in the input field.
This test opens a web page with a date picker, selects a specific date, and verifies the date is correctly set in the input field.
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 DatePickerTest(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/datepicker') def test_select_date(self): driver = self.driver wait = WebDriverWait(driver, 10) # Wait for date picker input to be clickable date_input = wait.until(EC.element_to_be_clickable((By.ID, 'date-input'))) date_input.click() # Wait for the date picker widget to appear date_picker = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'ui-datepicker-calendar'))) # Select the date 15 from the calendar date_cell = date_picker.find_element(By.XPATH, ".//a[text()='15']") date_cell.click() # Verify the input value is set to the expected date string expected_date = '06/15/2024' actual_date = date_input.get_attribute('value') self.assertEqual(actual_date, expected_date, f"Date input value should be {expected_date}") def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, navigated to 'https://example.com/datepicker' page | - | PASS |
| 2 | Waits until date picker input with ID 'date-input' is clickable | Date input field is visible and ready for interaction | - | PASS |
| 3 | Clicks on the date picker input field to open the calendar widget | Date picker calendar widget appears on the page | - | PASS |
| 4 | Waits until the calendar widget with class 'ui-datepicker-calendar' is visible | Calendar widget is fully loaded and visible | - | PASS |
| 5 | Finds the date cell with text '15' inside the calendar and clicks it | Date '15' is selected in the calendar | - | PASS |
| 6 | Reads the value attribute of the date input field | Date input field shows the selected date string | Check if input value equals '06/15/2024' | PASS |
| 7 | Test ends and browser closes | Browser window is closed | - | PASS |