How to Write Test Cases for Keyboard Navigation (With Examples)

How to Write Test Cases for Keyboard Navigation (With Examples) is a critical skill for QA engineers, especially in today's web and mobile applications where accessibility and user experience are para

By · February 20, 2026 · 14 min read · How-To Guides

How to Write Test Cases for Keyboard Navigation (With Examples)

How to Write Test Cases for Keyboard Navigation (With Examples) is a critical skill for QA engineers, especially in today's web and mobile applications where accessibility and user experience are paramount. Keyboard navigation is essential for users who cannot or prefer not to use a mouse, and ensuring that your application is fully navigable via the keyboard is a must. This guide will walk you through the process of writing high-signal test cases for keyboard navigation, covering everything from test case anatomy to real-world examples and edge cases.

Understanding Test Case Anatomy

Before diving into the specifics of writing test cases for keyboard navigation, it's essential to understand the basic structure of a test case. A well-structured test case typically includes the following components:

Test Case ID

Test Case Title

Preconditions

Test Steps

  1. Click on the login page.
  2. Press the Tab key to navigate to the username field.
  3. Press the Tab key again to navigate to the password field.
  4. Press the Tab key again to navigate to the login button.

Expected Result

Actual Result

Status

Positive Test Cases for Keyboard Navigation

Positive test cases are designed to verify that the application behaves as expected under normal conditions. Here are some examples of positive test cases for keyboard navigation:

Verify Tab Order in Login Form

  1. Click on the login page.
  2. Press the Tab key to navigate to the username field.
  3. Press the Tab key again to navigate to the password field.
  4. Press the Tab key again to navigate to the login button.

Verify Navigation in Dropdown Menu

  1. Click on the homepage.
  2. Press the Tab key to navigate to the dropdown menu.
  3. Press the Enter key to open the dropdown.
  4. Use the Arrow keys to navigate through the dropdown items.
  5. Press the Enter key to select an item.

Verify Focus on Modal Dialog

  1. Click on the button to open the modal dialog.
  2. Press the Tab key to navigate through the elements in the modal.

Negative Test Cases for Keyboard Navigation

Negative test cases are designed to verify that the application behaves correctly under abnormal or unexpected conditions. Here are some examples of negative test cases for keyboard navigation:

Verify Focus Trapping in Modal Dialog

  1. Click on the button to open the modal dialog.
  2. Press the Tab key to navigate through the elements in the modal.
  3. Press the Shift + Tab key to navigate backward.
  4. Press the Esc key to close the modal.

Verify Focus Loss on Page Reload

  1. Click on the form.
  2. Press the Tab key to navigate to a specific input field.
  3. Refresh the page.

Verify Focus on Disabled Elements

  1. Click on the form.
  2. Press the Tab key to navigate through the form elements.

Edge and Boundary Test Cases for Keyboard Navigation

Edge and boundary test cases are designed to verify that the application behaves correctly under extreme conditions. These test cases often uncover issues that are not apparent during normal usage. Here are some examples of edge and boundary test cases for keyboard navigation:

Verify Focus on Large Forms

  1. Click on the form.
  2. Press the Tab key to navigate through all input fields.

Verify Focus on Nested Elements

  1. Click on the page.
  2. Press the Tab key to navigate to the nested button.

Verify Focus on Dynamic Content

  1. Click on the page.
  2. Trigger the dynamic content load.
  3. Press the Tab key to navigate to the newly loaded content.

Test Matrix for Keyboard Navigation

To ensure comprehensive coverage, it's useful to organize your test cases into a test matrix. This matrix can help you track the status of each test case and identify any gaps in your testing. Here is a sample test matrix for keyboard navigation:

Test Case IDTest Case TitlePreconditionsTest StepsExpected ResultActual ResultStatus
TC001Verify Tab Order in Login FormUser is on the login page1. Click on the login page. 2. Press the Tab key to navigate to the username field. 3. Press the Tab key again to navigate to the password field. 4. Press the Tab key again to navigate to the login button.The focus should move sequentially from the username field to the password field, and finally to the login button.The focus moves as expected.Pass
TC002Verify Navigation in Dropdown MenuUser is on the homepage with a dropdown menu1. Click on the homepage. 2. Press the Tab key to navigate to the dropdown menu. 3. Press the Enter key to open the dropdown. 4. Use the Arrow keys to navigate through the dropdown items. 5. Press the Enter key to select an item.The dropdown menu should open, and the user should be able to navigate through the items and select one using the keyboard.The dropdown menu opens and the user can navigate through the items.Pass
TC003Verify Focus on Modal DialogUser is on a page that triggers a modal dialog1. Click on the button to open the modal dialog. 2. Press the Tab key to navigate through the elements in the modal.The focus should be trapped within the modal dialog, and the user should be able to navigate through all elements using the Tab key.The focus is trapped within the modal dialog.Pass
TC004Verify Focus Trapping in Modal DialogUser is on a page that triggers a modal dialog1. Click on the button to open the modal dialog. 2. Press the Tab key to navigate through the elements in the modal. 3. Press the Shift + Tab key to navigate backward. 4. Press the Esc key to close the modal.The focus should not leave the modal dialog while it is open, and pressing the Esc key should close the modal and return focus to the element that triggered it.The focus is trapped within the modal dialog and the modal closes as expected.Pass
TC005Verify Focus Loss on Page ReloadUser is on a page with a form1. Click on the form. 2. Press the Tab key to navigate to a specific input field. 3. Refresh the page.After the page reloads, the focus should return to the first focusable element on the page.The focus returns to the first focusable element on the page.Pass
TC006Verify Focus on Disabled ElementsUser is on a page with disabled form elements1. Click on the form. 2. Press the Tab key to navigate through the form elements.The focus should skip over disabled elements and move to the next focusable element.The focus skips over disabled elements.Pass
TC007Verify Focus on Large FormsUser is on a page with a large form containing over 20 input fields1. Click on the form. 2. Press the Tab key to navigate through all input fields.The focus should move sequentially through all input fields without skipping any.The focus moves through all input fields.Pass
TC008Verify Focus on Nested ElementsUser is on a page with nested focusable elements (e.g., a button inside a div)1. Click on the page. 2. Press the Tab key to navigate to the nested button.The focus should move to the nested button, and the user should be able to interact with it.The focus moves to the nested button.Pass
TC009Verify Focus on Dynamic ContentUser is on a page that dynamically loads new content1. Click on the page. 2. Trigger the dynamic content load. 3. Press the Tab key to navigate to the newly loaded content.The focus should move to the newly loaded content, and the user should be able to interact with it.The focus moves to the newly loaded content.Pass

Data Setup for Keyboard Navigation Testing

Data setup is crucial for ensuring that your test cases are executed under the right conditions. Here are some considerations for setting up data for keyboard navigation testing:

Test Environments

Test Data

Browser and Device Configurations

Prioritization and Traceability of Test Cases

Prioritizing and tracing your test cases is essential for effective testing. Here are some strategies for prioritizing and tracing test cases for keyboard navigation:

Prioritization

Traceability

Manual and Automated Approaches to Keyboard Navigation Testing

Both manual and automated testing have their place in ensuring the quality of keyboard navigation. Here are some considerations for each approach:

Manual Testing

Automated Testing

Tools for Automated Testing

Example: Automating Keyboard Navigation with Selenium

Here is an example of how to automate keyboard navigation using Selenium in Python:


from selenium import webdriver
from selenium.webdriver.common.keys import Keys

# Initialize the WebDriver
driver = webdriver.Chrome()

# Navigate to the login page
driver.get("https://example.com/login")

# Locate the username and password fields
username_field = driver.find_element_by_name("username")
password_field = driver.find_element_by_name("password")
login_button = driver.find_element_by_id("login-button")

# Simulate tab navigation
username_field.send_keys(Keys.TAB)
password_field.send_keys(Keys.TAB)
login_button.send_keys(Keys.TAB)

# Verify the focus is on the login button
assert login_button == driver.switch_to.active_element

# Close the browser
driver.quit()

Real-World Examples of Edge Cases in Keyboard Navigation

Real-world applications often encounter edge cases that are not apparent during initial testing. Here are some examples of edge cases that can arise in production environments:

Focus Loss on Dynamic Elements

Inconsistent Focus Behavior on Different Browsers

Focus Trapping in Complex Modal Dialogs

Checklist for Keyboard Navigation Testing

To ensure that you cover all aspects of keyboard navigation testing, use this checklist:

Combining Designed Test Cases with Autonomous Exploration

While designed test cases are essential for ensuring that specific requirements are met, they may not cover all possible scenarios and edge cases. Autonomous exploration tools like SUSA can help fill these gaps by exploring the application in a more comprehensive and dynamic way.

How SUSA Can Help

SUSA is an autonomous QA platform that can explore your application and identify issues related to keyboard navigation. By uploading an APK or pointing it at a web URL, SUSA can:

Example: Using SUSA for Keyboard Navigation Testing

Here is an example of how to use SUSA for keyboard navigation testing:

  1. Install SUSA:
  2. 
       pip install susatest-agent
    
  1. Run SUSA :
  2. 
       susatest-agent test https://example.com
    
  1. Review Results :

Conclusion and Takeaways

Writing high-signal test cases for keyboard navigation is crucial for ensuring that your application is accessible and user-friendly. By following the guidelines and examples provided in this guide, you can create comprehensive test cases that cover a wide range of scenarios, from positive and negative cases to edge and boundary conditions.

Key Takeaways

By combining designed test cases with autonomous exploration, you can ensure that your application is fully navigable via the keyboard, providing a better user experience for all users.

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 11 real users — finds bugs, accessibility violations, and security issues. No scripts. New to the category? Start with what autonomous product intelligence & QA means.

Try SUSA Free