Skip to content

Commit aebef74

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 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).
1 parent fd4893f commit aebef74

27 files changed

Lines changed: 3839 additions & 1 deletion

File tree

Gulpfile.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const {
3333
TESTS_GLOB,
3434
LEGACY_TESTS_GLOB,
3535
MULTIPLE_WINDOWS_TESTS_GLOB,
36+
ISOLATED_SESSIONS_TESTS_GLOB,
3637
HEADED_CHROME_FIREFOX_TESTS_GLOB,
3738
} = require('./gulp/constants/functional-test-globs');
3839

@@ -466,6 +467,13 @@ gulp.step('test-functional-local-multiple-windows-na-run', () => {
466467

467468
gulp.task('test-functional-local-multiple-windows-na', gulp.series('prepare-tests', 'test-functional-local-multiple-windows-na-run'));
468469

470+
// Isolated multi-session tests run against native automation Chrome
471+
gulp.step('test-functional-local-isolated-sessions-run', () => {
472+
return testFunctional(ISOLATED_SESSIONS_TESTS_GLOB, functionalTestConfig.testingEnvironmentNames.localChrome, { nativeAutomation: true });
473+
});
474+
475+
gulp.task('test-functional-local-isolated-sessions', gulp.series('prepare-tests', 'test-functional-local-isolated-sessions-run'));
476+
469477
gulp.step('test-functional-local-chrome-firefox-headed-run', () => {
470478
return testFunctional(HEADED_CHROME_FIREFOX_TESTS_GLOB, functionalTestConfig.testingEnvironmentNames.localBrowsersChromeFirefox);
471479
});

gulp/constants/functional-test-globs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +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';
23
const HEADED_CHROME_FIREFOX_TESTS_GLOB = ['test/functional/fixtures/live/test.js', 'test/functional/fixtures/ui/test.js'];
34
const COMPILER_SERVICE_TESTS_GLOB = 'test/functional/fixtures/compiler-service/test.js';
45
const LEGACY_TESTS_GLOB = 'test/functional/legacy-fixtures/**/test.js';
@@ -12,13 +13,15 @@ const SCREENSHOT_TESTS_GLOB = [
1213
const TESTS_GLOB = [
1314
BASIC_TESTS_GLOB,
1415
`!${MULTIPLE_WINDOWS_TESTS_GLOB}`,
16+
`!${ISOLATED_SESSIONS_TESTS_GLOB}`,
1517
`!${COMPILER_SERVICE_TESTS_GLOB}`,
1618
];
1719

1820
module.exports = {
1921
TESTS_GLOB,
2022
LEGACY_TESTS_GLOB,
2123
MULTIPLE_WINDOWS_TESTS_GLOB,
24+
ISOLATED_SESSIONS_TESTS_GLOB,
2225
BASIC_TESTS_GLOB,
2326
COMPILER_SERVICE_TESTS_GLOB,
2427
SCREENSHOT_TESTS_GLOB,

src/api/test-controller/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,23 @@ export default class TestController {
647647
[delegatedAPI(ReportCommand.methodName)] (...args) {
648648
return this.enqueueCommand(ReportCommand, { args });
649649
}
650+
651+
// isolated session opener — creates a CDP-isolated browser context
652+
_openIsolatedSession$ () {
653+
const callsite = getCallsiteForMethod('openIsolatedSession');
654+
655+
return this._enqueueTask('openIsolatedSession', () => {
656+
return async () => {
657+
if (!this.testRun.isNativeAutomation)
658+
throw new Error('openIsolatedSession requires Native Automation mode');
659+
660+
const isolatedSession = await this.testRun.createIsolatedSession();
661+
662+
return isolatedSession.controller;
663+
};
664+
}, callsite);
665+
}
666+
650667
shouldStop (command) {
651668
// NOTE: should always stop on Debug command
652669
return command === 'debug';

0 commit comments

Comments
 (0)