Test Overview
This test opens a web page with a form, fills in the input fields, submits the form, and verifies that the submission was successful by checking the confirmation message.
This test opens a web page with a form, fills in the input fields, submits the form, and verifies that the submission was successful by checking the confirmation message.
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 TestFormSubmission(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/contact') def test_submit_form(self): driver = self.driver # Find the name input and enter text name_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'name')) ) name_input.send_keys('Alice') # Find the email input and enter text email_input = driver.find_element(By.ID, 'email') email_input.send_keys('alice@example.com') # Find the message textarea and enter text message_input = driver.find_element(By.ID, 'message') message_input.send_keys('Hello, this is a test message.') # Submit the form by clicking the submit button submit_button = driver.find_element(By.ID, 'submit-btn') submit_button.click() # Wait for confirmation message to appear confirmation = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, 'confirmation')) ) # Verify the confirmation text self.assertEqual(confirmation.text, 'Thank you for your message!') 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, ready to load the page | - | PASS |
| 2 | Navigates to 'https://example.com/contact' | Contact page with form is loaded | Page loaded with form elements present | PASS |
| 3 | Finds the name input field by ID 'name' | Name input field is located and ready for input | Element with ID 'name' is present | PASS |
| 4 | Enters 'Alice' into the name input field | Name input field contains text 'Alice' | Input field value is 'Alice' | PASS |
| 5 | Finds the email input field by ID 'email' | Email input field is located and ready for input | Element with ID 'email' is present | PASS |
| 6 | Enters 'alice@example.com' into the email input field | Email input field contains text 'alice@example.com' | Input field value is 'alice@example.com' | PASS |
| 7 | Finds the message textarea by ID 'message' | Message textarea is located and ready for input | Element with ID 'message' is present | PASS |
| 8 | Enters 'Hello, this is a test message.' into the message textarea | Message textarea contains the test message | Textarea value matches the entered message | PASS |
| 9 | Finds the submit button by ID 'submit-btn' and clicks it | Form is submitted, page processes submission | Submit button is clickable and clicked | PASS |
| 10 | Waits for confirmation message with ID 'confirmation' to appear | Confirmation message is visible on the page | Element with ID 'confirmation' is visible | PASS |
| 11 | Checks that confirmation text equals 'Thank you for your message!' | Confirmation text is displayed correctly | Text matches expected confirmation message | PASS |
| 12 | Test ends and browser closes | Browser window is closed | - | PASS |