Mechasm supports running tests that span across multiple independent browser sessions within the same test run. This powerful feature is essential for testing real-time collaboration, messaging, and multi-user workflows.
What is a Context?
A "browser context" is an isolated incognito-like session within a single browser instance. Each context has its own isolated:
- Cookies
- Local Storage
- Session Storage
- IndexedDB
- Cache
By default, every test runs in a single primary context (often called the default session).
Using Multiple Contexts
You can switch between different contexts in your test using the Switch Context step. This tells the test runner to execute all subsequent steps in a different browser session.
How to Switch Contexts
- Add a Switch Context step to your test.
- Provide a Context ID (e.g.,
secondUser,adminView). - Set the Isolate Context flag (enabled by default).
When the test reaches this step, it will spawn a completely fresh, isolated browser session and switch focus to it.
Switching Back
To return to your original session, simply add another Switch Context step and provide the original Context ID (which is default for the primary session). The test will resume exactly where it left off in that session, with all state intact.
Common Use Cases
1. Chat and Messaging Apps
Test that a message sent by User A is instantly received by User B.
- Session 1 (
default): Log in as User A, navigate to chat, send a message. - Session 2 (
secondUser): Log in as User B, navigate to chat, verify the message appears.
2. Real-time Collaboration (e.g., Google Docs)
Verify that changes made by one user are reflected on another user's screen simultaneously.
- Session 1 (
default): Open a document, type "Hello World". - Session 2 (
collaborator): Open the same document, verify "Hello World" is visible.
3. Role-based Access Control (RBAC)
Test workflows that require interactions between users with different permissions.
- Session 1 (
user): Request a refund. - Session 2 (
manager): Log in to admin dashboard, approve the refund. - Session 1 (
user): Switch back to the user session, verify the refund status updated to "Approved".
Multi-Context Assets
When running a test across multiple contexts, Mechasm automatically isolates the debugging assets for clarity:
- Videos: You will see multiple tabs in the video player ("Primary Session", "secondUser Session"). Each tab shows exactly what happened in that specific browser window.
- Trace Viewer: The Trace Viewer also provides a tabbed interface. You can inspect the network requests, DOM snapshots, and console logs independently for each context, all synced to the global test timeline.