Test Overview
This test opens a web page with a text input field, enters some text, then clears the input field. It verifies that the input field is empty after clearing.
This test opens a web page with a text input field, enters some text, then clears the input field. It verifies that the input field is empty after clearing.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options import unittest class TestClearInputField(unittest.TestCase): def setUp(self): options = Options() options.add_argument('--headless') self.driver = webdriver.Chrome(service=Service(), options=options) self.driver.get('https://example.com/input') def test_clear_input_field(self): driver = self.driver input_field = driver.find_element(By.ID, 'username') input_field.send_keys('testuser') input_field.clear() self.assertEqual(input_field.get_attribute('value'), '') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens in headless mode | Browser is ready but no page loaded yet | - | PASS |
| 2 | Browser navigates to 'https://example.com/input' | Page with input field having id 'username' is loaded | - | PASS |
| 3 | Find input field by ID 'username' | Input field element is located | - | PASS |
| 4 | Send keys 'testuser' to input field | Input field contains text 'testuser' | - | PASS |
| 5 | Clear the input field using clear() method | Input field is empty | - | PASS |
| 6 | Assert that input field value is empty string | Input field value is '' | input_field.get_attribute('value') == '' | PASS |
| 7 | Close the browser and end test | Browser closed | - | PASS |