Button Automation Practice
Master button interactions in Selenium, Playwright & Cypress โ single click, double-click, right-click, disabled state, click-and-hold, coordinates, and computed styles.
| ID | Scenario | Type | Priority | |
|---|---|---|---|---|
| BTN_001 | Button is clickable and triggers its action Expected: Result text updates after a single click โ
positivehigh | positive | high | |
| BTN_002 | Button displays the correct label text Expected: Visible label matches the expected string exactly โ
positivemedium | positive | medium | |
| BTN_003 | Single click triggers the correct action Expected: Only the targeted result changes; others stay unchanged โ
positivehigh | positive | high | |
| BTN_004 | Double-click button triggers a double-click action Expected: Result reads "Double clicked!" after a dblclick โ
positivehigh | positive | high | |
| BTN_005 | Right-click button opens the context action Expected: Result confirms the context menu was triggered โ
positivemedium | positive | medium | |
| BTN_006 | Disabled button cannot be clicked Expected: Button is disabled and no action fires โ negativehigh | negative | high | |
| BTN_007 | Enabled button reports an enabled state Expected: Enabled buttons return isEnabled() === true โ
positivemedium | positive | medium | |
| BTN_008 | Button stays usable across viewport sizes Expected: Button remains visible and clickable on mobile and desktop widths โ ๏ธ edgemedium | edge | medium | |
| BTN_009 | Button is operable via keyboard Expected: Focusing and pressing Enter/Space triggers the action โ
positivehigh | positive | high | |
| BTN_010 | Button is exposed to screen readers Expected: Element has role=button and an accessible name โ
positivemedium | positive | medium | |
| BTN_011 | Hover state is visually distinct Expected: Background/style changes on hover โ ๏ธ edgelow | edge | low | |
| BTN_012 | Result state resets after a page refresh Expected: Reloading restores each result to its initial text โ ๏ธ edgelow | edge | low | |
| BTN_013 | Click-and-hold completes after 1.5 seconds Expected: Holding for 1.5s reports success; early release does not โ ๏ธ edgemedium | edge | medium | |
| BTN_014 | Button does not overlap adjacent elements Expected: Bounding boxes of neighbouring controls do not intersect โ ๏ธ edgelow | edge | low | |
| BTN_015 | Page loads without console errors Expected: No uncaught errors are logged during load โ
positivehigh | positive | high |
Buttons are one of the most important UI targets in automation. This page walks through the core actions you will use across Playwright, Selenium, and Cypress.
Single click is the baseline interaction. Use it to trigger navigation, updates, and normal action buttons.
// Playwright
await page.locator('#clickBtn').click();
await expect(page.locator('#clickResult')).toBeVisible();Double click requires its own framework-specific command. A normal click will not trigger a double-click event.
// Playwright
await page.locator('#doubleClickBtn').dblclick();Right click is useful for context-menu style flows. Framework support differs slightly, but all three can handle it.
// Playwright
await page.locator('#rightClickBtn').click({ button: 'right' });For disabled controls, assert state instead of forcing interaction. This is more stable and more realistic.
// Playwright
await expect(page.locator('#disabledBtn')).toBeDisabled();Text-change validation is a good way to assert that a button action actually caused a visible UI update.
// Playwright
const before = await page.locator('#toggleBtn').textContent();
await page.locator('#toggleBtn').click();Keyboard support matters for accessibility and test realism. A focused button should respond to Enter consistently.
// Playwright
await page.locator('#submitBtn').press('Enter');Quick reference across all three frameworks.
| Action | Selenium | Playwright JS | Playwright PY | Cypress |
|---|---|---|---|---|
| Single click | element.click() | locator.click() | locator.click() | .click() |
| Double click | actions.doubleClick(el) | locator.dblclick() | locator.dblclick() | .dblclick() |
| Right click | actions.contextClick(el) | click({ button: 'right' }) | click(button='right') | .rightclick() |
| Disabled assert | !element.isEnabled() | expect(locator).toBeDisabled() | expect(locator).to_be_disabled() | .should('be.disabled') |
| Keyboard Enter | sendKeys(Keys.ENTER) | locator.press('Enter') | locator.press('Enter') | .type('{enter}') |