Test Overview
This test opens a webpage, finds a button, clicks and holds it, then verifies that the hold action triggered a visible change on the page.
This test opens a webpage, finds a button, clicks and holds it, then verifies that the hold action triggered a visible change on the page.
from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains 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 TestClickAndHold(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/click-and-hold') self.wait = WebDriverWait(self.driver, 10) def test_click_and_hold_button(self): driver = self.driver wait = self.wait button = wait.until(EC.presence_of_element_located((By.ID, 'hold-button'))) actions = ActionChains(driver) actions.click_and_hold(button).perform() # Verify that holding the button changes text message = wait.until(EC.visibility_of_element_located((By.ID, 'message'))) self.assertEqual(message.text, 'Button is being held') 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 URL | - | PASS |
| 2 | Navigates to 'https://example.com/click-and-hold' | Page loads with a button having id 'hold-button' and a hidden message element with id 'message' | - | PASS |
| 3 | Waits until the button with id 'hold-button' is present | Button is found on the page | Element presence confirmed | PASS |
| 4 | Performs click and hold action on the button | Button is pressed and held down | - | PASS |
| 5 | Waits until the message element with id 'message' becomes visible | Message element is visible with text 'Button is being held' | Message text equals 'Button is being held' | PASS |
| 6 | Test ends and browser closes | Browser window closed | - | PASS |