Test Overview
This test checks if pressing and releasing key combinations (like Ctrl + A) works correctly on a text input field. It verifies that the text is selected after the key combination.
This test checks if pressing and releasing key combinations (like Ctrl + A) works correctly on a text input field. It verifies that the text is selected after the key combination.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class TestKeyCombinations(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_text') self.driver.switch_to.frame('iframeResult') def test_ctrl_a_select_all(self): driver = self.driver input_box = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'fname')) ) input_box.clear() input_box.send_keys('Hello World') actions = ActionChains(driver) actions.key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform() selected_text = driver.execute_script("return arguments[0].value.substring(arguments[0].selectionStart, arguments[0].selectionEnd);", input_box) self.assertEqual(selected_text, 'Hello World') 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 opened with URL https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_input_text loaded | - | PASS |
| 2 | Switch to iframe 'iframeResult' to access input field | Inside iframe with input field visible | Check iframe is switched successfully | PASS |
| 3 | Wait until input box with id 'fname' is present | Input box is present and visible | Input box located successfully | PASS |
| 4 | Clear input box and type 'Hello World' | Input box contains text 'Hello World' | Input box text is 'Hello World' | PASS |
| 5 | Perform key combination: hold Ctrl, press 'a', release Ctrl | Text 'Hello World' is selected in input box | Selected text equals 'Hello World' | PASS |
| 6 | Test ends and browser closes | Browser closed | - | PASS |