Test Overview
This test opens a web page, finds a button, performs a right-click (context click) on it, and verifies that the context menu appears.
This test opens a web page, finds a button, performs a right-click (context click) on it, and verifies that the context menu appears.
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 TestRightClick(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/context-menu') self.wait = WebDriverWait(self.driver, 10) def test_right_click_context_menu(self): driver = self.driver wait = self.wait button = wait.until(EC.presence_of_element_located((By.ID, 'right-click-btn'))) ActionChains(driver).context_click(button).perform() context_menu = wait.until(EC.visibility_of_element_located((By.ID, 'context-menu'))) self.assertTrue(context_menu.is_displayed()) 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 navigate | - | PASS |
| 2 | Browser navigates to 'https://example.com/context-menu' | Page with a button having id 'right-click-btn' is loaded | Wait until element with ID 'right-click-btn' is present | PASS |
| 3 | Find element with ID 'right-click-btn' | Button element is located on the page | Element is found and ready for interaction | PASS |
| 4 | Perform right-click (context click) on the button | Context menu should appear after right-click | - | PASS |
| 5 | Wait for context menu with ID 'context-menu' to be visible | Context menu is displayed on the page | Verify context menu is displayed (is_displayed() returns True) | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |