feat: add t.openIsolatedSession() for multi-user e2e tests via CDP#8492
Open
sam-yh wants to merge 1 commit intoDevExpress:masterfrom
Open
feat: add t.openIsolatedSession() for multi-user e2e tests via CDP#8492sam-yh wants to merge 1 commit intoDevExpress:masterfrom
sam-yh wants to merge 1 commit intoDevExpress:masterfrom
Conversation
Add the ability to open fully isolated browser sessions within a single test. Each session gets its own Chrome browser context (separate cookies, localStorage, sessionStorage, service workers) via CDP's Target.createBrowserContext(). Includes 40 functional tests, selector chaining support, t2.run() for transparent Selector/ClientFunction evaluation, and automatic cleanup. Requires Native Automation mode (Chrome only).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: This feature was developed with the assistance of Claude Opus 4.6 (Anthropic) and should be considered "vibe coded." We have been running it in production for our multi-user e2e test suite and all 40 functional tests pass, but the codebase has not undergone traditional peer review beyond AI-assisted iteration. We welcome feedback on the implementation approach and are happy to iterate.
Summary
Adds
t.openIsolatedSession()— the ability to open fully isolated browser sessions within a single test. Each session gets its own Chrome browser context (separate cookies, localStorage, sessionStorage, service workers) via CDP'sTarget.createBrowserContext().This enables multi-user e2e tests: doctor + patient in a video call, two users editing the same document, concurrent booking scenarios — all within a single test.
Motivation
Currently, testing multi-user scenarios requires either:
This PR provides a native solution:
t.openIsolatedSession()returns a second test controller (t2) backed by a completely isolated Chrome browser context.API
Supported commands
Command-based: click, rightClick, doubleClick, hover, drag, dragToElement, typeText, pressKey, selectText, scroll, scrollBy, scrollIntoView, dispatchEvent, navigateTo, wait, eval, expect, useRole, getCookies, setCookies, deleteCookies
Direct session methods: setHttpAuth, setWindowBounds, takeScreenshot, takeElementScreenshot, maximizeWindow, resizeWindow, setFilesToUpload, setPageLoadTimeout, switchToIframe, switchToMainWindow
Selector chaining: withText, withExactText, filterVisible, filterHidden, nth, find, parent, child, sibling, nextSibling, prevSibling, withAttribute
Requirements
--experimental-multiple-windowsornativeAutomation: true)Target.createBrowserContext)Architecture
Three new files, six modified files:
New files:
src/test-run/isolated-session.ts— Core runtime class. Holds CDP client, executes commands via CDPsrc/api/test-controller/isolated.js— Thet2controller. Mirrors TestController's delegatedAPI patternsrc/native-automation/isolated-window.ts— Thin NativeAutomationBase wrapper for isolated tabsModified files:
src/browser/provider/built-in/dedicated/chrome/cdp-client/index.ts—createIsolatedContext(),disposeIsolatedContext()src/browser/provider/built-in/dedicated/chrome/index.js—createIsolatedSession(),disposeIsolatedSession()src/api/test-controller/index.js—_openIsolatedSession$()methodsrc/test-run/index.ts— Isolated session lifecycle (create, dispose, find)src/client-functions/selectors/selector-builder.js—counterMode,getVisibleValueModepropertiessrc/test-run/commands/execute-client-function.js— Same two propertiesKey design decisions:
TestRun._done()Tests
40 functional tests in
test/functional/fixtures/isolated-sessions/:Run tests:
Documentation
t.openIsolatedSession()→IsolatedTestControllerOpens a new browser window in a fully isolated Chrome browser context. Returns an
IsolatedTestController(commonly namedt2) with a subset of the standard TestCafe API.Requires: Native Automation mode.
The isolated session has completely separate cookies, localStorage, sessionStorage, and service workers from the main session and from other isolated sessions.
Sessions are automatically cleaned up when the test ends. The CDP WebSocket is closed and
Target.disposeBrowserContext()destroys the context.t2.run(callback)Executes a callback where Selector queries and ClientFunction evaluations target the isolated session's CDP tab. Inside the callback,
Selector.exists,Selector.visible,Selector.innerText, andClientFunctionall evaluate in the isolated tab. Action commands (click, typeText, etc.) still require usingt2directly.