Skip to main content

Overview

The Go Back step simulates clicking the browser’s back button, navigating to the previous page in the browser history. Use it to test back navigation, return to previous pages after actions, or verify that browser history works correctly.

When to Use Go Back

Use Go Back when you need to:
  • Test back navigation: Verify the back button works correctly in your app
  • Return after submission: Go back after completing a form or action
  • Test multi-step workflows: Navigate backward through multi-page processes
  • Verify state preservation: Check that page state is preserved when returning
  • Test browser history: Ensure your single-page app correctly manages history

How It Works

Go Back navigates to the previous page in the browser’s history stack, just like clicking the browser’s back button. It triggers a full page navigation (or client-side routing for SPAs), returning to the exact state the previous page was in. Important: Go Back requires there to be a previous page in the browser history. If your test starts on a page with no previous history, Go Back will have no effect.

Real-World Examples

Returning After Form Submission

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

Step 2: Click
  Locator: .product-card[data-id='123']

Step 3: Check URL
  Pattern: /products/123

Step 4: Click
  Locator: button[data-action='add-to-cart']

Step 5: Check Visibility
  Locator: .success-notification
  Assertion: Is visible

Step 6: Go Back

Step 7: Check URL
  Pattern: /products

Step 8: Check Visibility
  Locator: .product-grid
  Assertion: Is visible
Why this works: Add a product to cart, then navigate back to the product list.

Testing Multi-Step Workflow Navigation

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

Step 2: Fill
  Locator: input[name='email']
  Text: [email protected]

Step 3: Click
  Locator: button[data-action='continue']

Step 4: Check URL
  Pattern: /checkout/shipping

Step 5: Go Back

Step 6: Check URL
  Pattern: /checkout

Step 7: Check Text
  Locator: input[name='email']
  Expected Text: [email protected]
Why this works: Move forward in checkout, go back, and verify form data persists.

Verifying Single-Page App History

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

Step 2: Click
  Locator: a[href='/about']

Step 3: Check URL
  Pattern: /about

Step 4: Click
  Locator: a[href='/contact']

Step 5: Check URL
  Pattern: /contact

Step 6: Go Back

Step 7: Check URL
  Pattern: /about

Step 8: Go Back

Step 9: Check URL
  Pattern: /
Why this works: Verify that client-side routing correctly manages browser history in a SPA.

Testing State After Back Navigation

Step 1: Navigate
  URL: https://example.com/search?q=laptop

Step 2: Scroll
  Direction: Down
  Pixels: 500
  Locator: body

Step 3: Click
  Locator: .search-result:nth-child(5)

Step 4: Go Back

Step 5: Check URL
  Pattern: ?q=laptop

Step 6: Check Visibility
  Locator: .search-result:nth-child(5)
  Assertion: Is visible
Why this works: Verify that scroll position and search state are preserved after going back.

Best Practices

Ensure History Exists

  • Don’t use Go Back as the first step in a test
  • Navigate to at least one page before using Go Back
  • Verify there’s a previous page in history
  • Consider using Navigate if you need to go to a specific URL

Wait After Navigation

  • Add Wait for Element after Go Back
  • Wait for key page elements to appear
  • Account for page load time
  • Handle loading states appropriately

Verify the Result

Always check that back navigation worked:

Test State Preservation

Check what should and shouldn’t persist:
  • Form data might be preserved (browser-dependent)
  • Scroll position might be restored
  • Dynamic content might need reloading
  • Test both client-side and server-rendered pages

Troubleshooting

Nothing Happens

Symptom: Go Back step runs but page doesn’t change Solution:
  • Verify there’s a previous page in browser history
  • Check that your test navigated to at least one page before Go Back
  • Use Navigate instead if you need to go to a specific URL
  • Add Wait for Element to ensure navigation completes

Wrong Page Appears

Symptom: Go Back navigates to an unexpected page Solution:
  • Review your test flow to understand the history stack
  • Check if redirects added unexpected history entries
  • Verify SPA routing is managing history correctly
  • Use Check URL to confirm the destination

State Lost After Back

Symptom: Form data or page state is lost when going back Solution:
  • This is often browser-dependent behavior
  • Some frameworks don’t preserve state on back navigation
  • Test manually to confirm the expected behavior
  • Consider if state should actually persist

SPA Navigation Issues

Symptom: Back navigation doesn’t work in single-page app Solution:
  • Verify your SPA framework manages browser history correctly
  • Check that client-side routing pushes history states
  • Ensure back navigation triggers proper route changes
  • Test with and without JavaScript to isolate the issue