Skip to content

Commit bbe3112

Browse files
committed
feat: add t.openIsolatedSession() for multi-user e2e tests via CDP
Add the ability to open fully isolated browser sessions within a single test. Each isolated session gets its own Chrome browser context (separate cookies, localStorage, sessionStorage, service workers) via CDP Target.createBrowserContext(). This enables multi-user e2e tests — e.g. doctor + patient in a video call, two users editing the same document, concurrent booking scenarios — all in one test without needing multiple TestCafe instances. API: const t2 = await t.openIsolatedSession(); await t2.navigateTo('https://example.com'); await t2.click('#btn'); await t2.typeText('#input', 'text'); Supported: click, rightClick, doubleClick, hover, drag, dragToElement, typeText, pressKey, selectText, scroll, scrollBy, scrollIntoView, dispatchEvent, navigateTo, wait, eval, expect, useRole, getCookies, setCookies, deleteCookies, takeScreenshot, takeElementScreenshot, setFilesToUpload, setPageLoadTimeout, maximizeWindow, resizeWindow, switchToIframe, switchToMainWindow. Selector chaining (withText, nth, filterVisible, find, withAttribute, etc.) works. t2.run() provides transparent Selector/ClientFunction evaluation in the isolated tab. Requires Native Automation mode (Chrome only). Includes 40 functional tests covering isolation, commands, selector chaining, t2.run(), cookies, iframes, screenshots, file upload, and window management.
1 parent 62c28b4 commit bbe3112

15 files changed

Lines changed: 3780 additions & 2617 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ Gemfile.lock
1414
.DS_Store
1515
!gulp
1616
/test/functional/fixtures/**/package.json
17-
_uploads_/
18-
testcafe-*.tgz
19-
yarn.lock

.gitlab-ci.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 294 additions & 388 deletions
Large diffs are not rendered by default.

gulp/constants/functional-test-globs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const MULTIPLE_WINDOWS_TESTS_GLOB = 'test/functional/fixtures/multiple-windows/test.js';
2-
const ISOLATED_SESSIONS_TESTS_GLOB = 'test/functional/fixtures/isolated-sessions/test.js'; // SAMEDI
2+
const ISOLATED_SESSIONS_TESTS_GLOB = 'test/functional/fixtures/isolated-sessions/test.js';
33
const HEADED_CHROME_FIREFOX_TESTS_GLOB = ['test/functional/fixtures/live/test.js', 'test/functional/fixtures/ui/test.js'];
44
const COMPILER_SERVICE_TESTS_GLOB = 'test/functional/fixtures/compiler-service/test.js';
55
const LEGACY_TESTS_GLOB = 'test/functional/legacy-fixtures/**/test.js';
@@ -13,15 +13,15 @@ const SCREENSHOT_TESTS_GLOB = [
1313
const TESTS_GLOB = [
1414
BASIC_TESTS_GLOB,
1515
`!${MULTIPLE_WINDOWS_TESTS_GLOB}`,
16-
`!${ISOLATED_SESSIONS_TESTS_GLOB}`, // SAMEDI
16+
`!${ISOLATED_SESSIONS_TESTS_GLOB}`,
1717
`!${COMPILER_SERVICE_TESTS_GLOB}`,
1818
];
1919

2020
module.exports = {
2121
TESTS_GLOB,
2222
LEGACY_TESTS_GLOB,
2323
MULTIPLE_WINDOWS_TESTS_GLOB,
24-
ISOLATED_SESSIONS_TESTS_GLOB, // SAMEDI
24+
ISOLATED_SESSIONS_TESTS_GLOB,
2525
BASIC_TESTS_GLOB,
2626
COMPILER_SERVICE_TESTS_GLOB,
2727
SCREENSHOT_TESTS_GLOB,

package-lock.json

Lines changed: 3464 additions & 2187 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@qa/testcafe-fork",
2+
"name": "testcafe",
33
"description": "Automated browser testing for the modern web development stack.",
44
"license": "MIT",
55
"version": "3.7.4",
@@ -54,7 +54,6 @@
5454
"scripts": {
5555
"test": "gulp travis",
5656
"build": "gulp build",
57-
"prepare": "gulp build",
5857
"test-functional-local-headless-chrome-run-esm": "cross-env NODE_OPTIONS='--experimental-loader=./lib/compiler/esm-loader.js' gulp test-functional-local-headless-chrome-run --steps-as-tasks",
5958
"test-functional-local-headless-chrome-esm": "npm run build && npm run test-functional-local-headless-chrome-run-esm",
6059
"publish-please-only": "publish-please",
@@ -230,7 +229,7 @@
230229
"sinon": "^7.3.0",
231230
"stack-chain": "^2.0.0",
232231
"strip-ansi": "^3.0.0",
233-
"testcafe-browser-provider-browserstack": "^1.14.1",
232+
"testcafe-browser-provider-browserstack": "^1.14.1",
234233
"tslib": "^2.4.0",
235234
"uglify-js": "~3.10.4"
236235
},

src/api/test-controller/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ export default class TestController {
648648
return this.enqueueCommand(ReportCommand, { args });
649649
}
650650

651-
// SAMEDI: isolated session opener — creates a CDP-isolated browser context
651+
// Open an isolated browser session via CDP Target.createBrowserContext
652652
_openIsolatedSession$ () {
653653
const callsite = getCallsiteForMethod('openIsolatedSession');
654654

src/api/test-controller/isolated.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SAMEDI: IsolatedTestController — test controller for CDP-isolated browser sessions (t2 API)
1+
// IsolatedTestController — test controller for CDP-isolated browser sessions (t2 API)
22
//
33
// The t2 object returned by t.openIsolatedSession(). Mirrors TestController's
44
// delegatedAPI pattern but routes commands to IsolatedSession.executeCommand()

src/browser/provider/built-in/dedicated/chrome/cdp-client/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class BrowserClient {
7171
private _videoFramesBuffer: VideoFrameData[];
7272
private _lastFrame: VideoFrameData | null;
7373
private _screencastFrameListenerAttached = false;
74-
private _browserLevelClient: remoteChrome.ProtocolApi | null = null; // SAMEDI
74+
private _browserLevelClient: remoteChrome.ProtocolApi | null = null;
7575

7676
public constructor (runtimeInfo: RuntimeInfo) {
7777
this._runtimeInfo = runtimeInfo;
@@ -461,7 +461,7 @@ export class BrowserClient {
461461
}
462462
}
463463

464-
// SAMEDI: browser-level CDP client + isolated context creation/disposal
464+
465465
private async _getBrowserLevelClient (): Promise<remoteChrome.ProtocolApi> {
466466
if (this._browserLevelClient)
467467
return this._browserLevelClient;

src/browser/provider/built-in/dedicated/chrome/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from './local-chrome';
1111
import { GET_WINDOW_DIMENSIONS_INFO_SCRIPT } from '../../../utils/client-functions';
1212
import { BrowserClient } from './cdp-client';
13-
import { NativeAutomationIsolatedWindow } from '../../../../../native-automation/isolated-window'; // SAMEDI
13+
import { NativeAutomationIsolatedWindow } from '../../../../../native-automation/isolated-window';
1414
import { dispatchEvent as dispatchNativeAutomationEvent, navigateTo } from '../../../../../native-automation/utils/cdp';
1515
import { chromeBrowserProviderLogger } from '../../../../../utils/debug-loggers';
1616
import { EventType } from '../../../../../native-automation/types';
@@ -62,7 +62,7 @@ export default {
6262
await nativeAutomation.start();
6363

6464
runtimeInfo.nativeAutomation = nativeAutomation;
65-
runtimeInfo.nativeAutomationOptions = nativeAutomationOptions; // SAMEDI: store for isolated session creation
65+
runtimeInfo.nativeAutomationOptions = nativeAutomationOptions;
6666
},
6767

6868
async _startChrome (startOptions, pageUrl) {
@@ -223,7 +223,7 @@ export default {
223223
}
224224
},
225225

226-
// SAMEDI: create/dispose isolated browser contexts via CDP
226+
227227
async createIsolatedSession (browserId) {
228228
const runtimeInfo = this.openedBrowsers[browserId];
229229
const browserClient = runtimeInfo.browserClient;

0 commit comments

Comments
 (0)