close
  • English
  • Browser mode (experimental)

    Rstest provides Browser Mode, allowing you to run tests in a real browser instead of simulated environments like jsdom or happy-dom.

    What is browser Mode?

    Browser Mode uses Playwright to execute your test code in real browsers (Chromium, Firefox, or WebKit). This means your tests run with the exact same browser APIs and behaviors as in production.

    Locator API

    Browser Mode now supports a Playwright-style Locator workflow: you can use page.getBy* for element queries, then use expect.element(locator) for auto-waiting assertions.

    This approach is ideal when you want semantic queries (role/label/text) and chainable assertions, making component tests and DOM tests closer to real user interaction semantics.

    See User interactions for detailed usage.

    When to use browser mode

    Use this decision tree to determine if you need Browser Mode:

    Depends on real browser APIs? ─── Yes ─▶ ✅ Browser Mode
             │ No
    
    Need cross-browser testing?  ─── Yes ─▶ ✅ Browser Mode
             │ No
    
    Unexpected behavior in jsdom? ── Yes ─▶ ✅ Browser Mode
             │ No
    
        💡 jsdom is fine
    Recommendation

    Even if your tests work fine in jsdom, we still recommend using Browser Mode. See the comparison table below for specific advantages.

    Browser mode vs jsdom/happy-dom

    Browser Mode and jsdom/happy-dom represent different trade-offs: Browser Mode provides full browser compatibility and visual debugging but consumes more resources; jsdom/happy-dom runs faster and lighter but can only simulate a subset of browser APIs.

    FeatureBrowser Modejsdom / happy-dom
    Browser API coverage✅ Full support⚠️ Partial simulation
    Canvas / WebGL✅ Native support❌ Unsupported or needs polyfill
    CSS computed styles✅ Real rendering⚠️ Limited support
    Web Workers✅ Native support❌ Unsupported
    Execution speed⚠️ Slower✅ Faster
    Resource usage⚠️ Higher✅ Lower
    Debugging experience✅ Visual debugging⚠️ Console only
    Cross-browser testing✅ Multiple browsers❌ Unsupported

    Next steps