Skip to main content

Overview

The Press Keys step simulates keyboard input including individual keys, keyboard shortcuts, and special function keys. It captures your actual key presses to ensure accurate simulation of keyboard interactions.

When to Use Press Keys

Use Press Keys when you need to:
  • Test keyboard shortcuts: Verify copy/paste, save, undo, and other shortcuts work correctly
  • Navigate with keyboard: Use Tab, Enter, Escape, and arrow keys to navigate your UI
  • Submit forms: Press Enter to submit forms without clicking buttons
  • Close modals: Press Escape to dismiss dialogs and overlays
  • Test accessibility: Verify keyboard-only navigation works for all users

How It Works

Press Keys captures the exact key combination you press during test creation and replays it during test execution. It sends all the same keyboard events a real user would - keydown, keypress, keyup - making it work with both native browser shortcuts and custom JavaScript key handlers. The step supports modifier keys (Control, Shift, Alt, Command), special keys (Enter, Tab, Escape), function keys (F1-F12), and regular letter/number keys.

Using the Press Keys Step

When you add a Press Keys step:

Capturing Your Key Combination

Click in the key capture field and press the exact keys you want to simulate. The step displays your combination in real-time (like “Control+C” or “Shift+Tab”). You can press:
  • Single keys: Enter, Escape, Tab, A, 1
  • Modifier combinations: Control+C, Alt+Tab, Shift+A
  • Multi-modifier combinations: Control+Shift+I, Command+Option+J
The capture interface records exactly what you press, ensuring perfect reproduction during tests.

Real-World Examples

Submitting a Form with Enter

Step 1: Fill
  Locator: input[name='search']
  Text: laptop

Step 2: Press Keys
  Keys: Enter

Step 3: Check URL
  Pattern: ?q=laptop
Why this works: Press Enter to submit a search form without clicking the submit button.

Closing a Modal with Escape

Step 1: Click
  Locator: button[data-action='help']

Step 2: Check Visibility
  Locator: .help-modal
  Assertion: Is visible

Step 3: Press Keys
  Keys: Escape

Step 4: Check Visibility
  Locator: .help-modal
  Assertion: Is not visible
Why this works: Verify that pressing Escape closes the modal dialog.

Keyboard Navigation

Step 1: Click
  Locator: input[name='firstName']

Step 2: Fill
  Locator: input[name='firstName']
  Text: John

Step 3: Press Keys
  Keys: Tab

Step 4: Fill
  Locator: input[name='lastName']
  Text: Doe

Step 5: Press Keys
  Keys: Tab

Step 6: Fill
  Locator: input[name='email']
  Text: [email protected]
Why this works: Use Tab to navigate between form fields like a keyboard-only user would.

Testing Copy/Paste

Step 1: Click
  Locator: .code-sample

Step 2: Press Keys
  Keys: Control+A

Step 3: Press Keys
  Keys: Control+C

Step 4: Click
  Locator: textarea[name='code']

Step 5: Press Keys
  Keys: Control+V

Step 6: Check Text
  Locator: textarea[name='code']
  Expected Text: function hello() { return 'world'; }
Why this works: Test that copy/paste functionality works correctly.

Browser Shortcuts

Step 1: Navigate
  URL: https://example.com

Step 2: Press Keys
  Keys: Control+T

Step 3: Navigate
  URL: https://example.com/about

Step 4: Press Keys
  Keys: Control+W
Why this works: Use browser shortcuts to open and close tabs (be careful - some shortcuts may not work in all test environments).

Best Practices

Test Keyboard Accessibility

  • Always verify keyboard-only navigation works
  • Test Tab order through forms and interactive elements
  • Ensure all actions are accessible without a mouse
  • Check that focus indicators are visible

Use Standard Shortcuts

  • Stick to common shortcuts (Control+C, Control+V, etc.)
  • Be aware of platform differences (Control on Windows/Linux, Command on Mac)
  • Test in your target browsers and operating systems
  • Avoid browser-specific shortcuts that may not work everywhere

Consider Focus State

  • Some shortcuts only work when specific elements have focus
  • Click or Fill to focus an element before pressing keys
  • Global shortcuts (like Control+T) work regardless of focus
  • Test both focused and unfocused states

Verify Results

Always check that key presses had the expected effect:

Troubleshooting

Keys Not Working

Symptom: Key combination doesn’t trigger expected action Solution:
  • Verify the application supports that keyboard shortcut
  • Check if the correct element has focus
  • Use Click to focus an element first if needed
  • Test the shortcut manually to confirm it works

Platform Differences

Symptom: Shortcuts work on one OS but not another Solution:
  • Windows/Linux use Control for most shortcuts
  • Mac uses Command instead of Control
  • Test on all platforms you support
  • Consider creating platform-specific test variants

Browser Interference

Symptom: Browser captures the shortcut instead of your app Solution:
  • Some browser shortcuts (Control+T, Control+W) may not work in automation
  • Your app can’t override all browser shortcuts
  • Test in the same browser environment as your users
  • Focus on application-specific shortcuts, not browser ones

Focus Issues

Symptom: Shortcut only works sometimes Solution:
  • Verify the right element has focus when keys are pressed
  • Add Click to focus an element first
  • Check if your app requires specific focus states
  • Test both focused and unfocused scenarios
  • Fill - For typing text (use Press Keys for keyboard shortcuts)
  • Click - Set focus before pressing keys
  • Check Visibility - Verify keyboard action results
  • Wait for Element - Wait for keyboard shortcut results