Skip to content

Commit

Permalink
experimental multiple windows after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Dec 18, 2023
1 parent 20b6159 commit 4a08352
Show file tree
Hide file tree
Showing 39 changed files with 481 additions and 149 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test-functional-local-multiple-windows-na.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test Functional (Multiple Windows in Native Automation mode)

on:
workflow_dispatch:
inputs:
sha:
description: 'The test commit SHA or ref'
required: true
default: 'master'
merged_sha:
description: 'The merge commit SHA'
deploy_run_id:
description: 'The ID of a deployment workspace run with artifacts'
jobs:
test:
uses: ./.github/workflows/test-functional.yml
with:
test-script: 'npx gulp test-functional-local-multiple-windows-na-run --steps-as-tasks'
display: ':99.0'
6 changes: 6 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,12 @@ gulp.step('test-functional-local-multiple-windows-run', () => {

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

gulp.step('test-functional-local-multiple-windows-na-run', () => {
return testFunctional(MULTIPLE_WINDOWS_TESTS_GLOB, functionalTestConfig.testingEnvironmentNames.localChrome, { nativeAutomation: true });
});

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

gulp.step('test-functional-local-chrome-firefox-headed-run', () => {
return testFunctional(HEADED_CHROME_FIREFOX_TESTS_GLOB, functionalTestConfig.testingEnvironmentNames.localBrowsersChromeFirefox);
});
Expand Down
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
"source-map-support": "^0.5.16",
"strip-bom": "^2.0.0",
"testcafe-browser-tools": "2.0.26",
"testcafe-hammerhead": "31.6.4",
"testcafe-hammerhead": "https://github.com/AlexKamaev/issues/raw/master/testcafe-hammerhead-31.7.0.tgz",
"testcafe-legacy-api": "5.1.6",
"testcafe-reporter-json": "^2.1.0",
"testcafe-reporter-list": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/api/test-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default class TestController {
_validateMultipleWindowCommand (apiMethodName) {
const { disableMultipleWindows, activeWindowId } = this.testRun;

if (this.testRun.isNativeAutomation)
if (this.testRun.isNativeAutomation && !this.testRun.isExperimentalMultipleWindows)
throw new MultipleWindowsModeIsNotSupportedInNativeAutomationModeError(apiMethodName);

if (disableMultipleWindows)
Expand Down
11 changes: 11 additions & 0 deletions src/browser/connection/gateway/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class BrowserConnectionGateway extends EventEmitter {
this._dispatch(`${SERVICE_ROUTES.initScript}/{id}`, proxy, BrowserConnectionGateway._onInitScriptResponse, 'POST');
this._dispatch(`${SERVICE_ROUTES.activeWindowId}/{id}`, proxy, BrowserConnectionGateway._onGetActiveWindowIdRequest, 'GET');
this._dispatch(`${SERVICE_ROUTES.activeWindowId}/{id}`, proxy, BrowserConnectionGateway._onSetActiveWindowIdRequest, 'POST');
this._dispatch(`${SERVICE_ROUTES.ensureWindowInNativeAutomation}/{id}`, proxy, BrowserConnectionGateway._ensureWindowInNativeAutomation, 'POST');
this._dispatch(`${SERVICE_ROUTES.closeWindow}/{id}`, proxy, BrowserConnectionGateway._onCloseWindowRequest, 'POST');
this._dispatch(`${SERVICE_ROUTES.openFileProtocol}/{id}`, proxy, BrowserConnectionGateway._onOpenFileProtocolRequest, 'POST');
this._dispatch(`${SERVICE_ROUTES.dispatchNativeAutomationEvent}/{id}`, proxy, BrowserConnectionGateway._onDispatchNativeAutomationEvent, 'POST');
Expand Down Expand Up @@ -202,6 +203,16 @@ export default class BrowserConnectionGateway extends EventEmitter {
}
}

private static async _ensureWindowInNativeAutomation (req: IncomingMessage, res: ServerResponse, connection: BrowserConnection): Promise<void> {
if (BrowserConnectionGateway._ensureConnectionReady(res, connection)) {
BrowserConnectionGateway._fetchRequestData(req, async data => {
const windowId = await connection.getNewWindowIdInNativeAutomation(JSON.parse(data).windowId);

respondWithJSON(res, { windowId });
});
}
}

private static _onSetActiveWindowIdRequest (req: IncomingMessage, res: ServerResponse, connection: BrowserConnection): void {
if (BrowserConnectionGateway._ensureConnectionReady(res, connection)) {
BrowserConnectionGateway._fetchRequestData(req, data => {
Expand Down
14 changes: 12 additions & 2 deletions src/browser/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { TestRun as LegacyTestRun } from 'testcafe-legacy-api';
import { Proxy } from 'testcafe-hammerhead';
import { NextTestRunInfo, OpenBrowserAdditionalOptions } from '../../shared/types';
import { EventType } from '../../native-automation/types';
import NativeAutomation from '../../native-automation';
import { NativeAutomationBase } from '../../native-automation';

const getBrowserConnectionDebugScope = (id: string): string => `testcafe:browser:connection:${id}`;

Expand Down Expand Up @@ -119,6 +119,7 @@ export default class BrowserConnection extends EventEmitter {
public heartbeatUrl = '';
public statusUrl = '';
public activeWindowIdUrl = '';
public ensureWindowInNativeAutomationUrl = '';
public closeWindowUrl = '';
public statusDoneUrl = '';
public heartbeatRelativeUrl = '';
Expand Down Expand Up @@ -202,6 +203,7 @@ export default class BrowserConnection extends EventEmitter {
this.statusDoneRelativeUrl = `${SERVICE_ROUTES.statusDone}/${this.id}`;
this.idleRelativeUrl = `${SERVICE_ROUTES.idle}/${this.id}`;
this.activeWindowIdUrl = `${SERVICE_ROUTES.activeWindowId}/${this.id}`;
this.ensureWindowInNativeAutomationUrl = `${SERVICE_ROUTES.ensureWindowInNativeAutomation}/${this.id}`;
this.closeWindowUrl = `${SERVICE_ROUTES.closeWindow}/${this.id}`;
this.openFileProtocolRelativeUrl = `${SERVICE_ROUTES.openFileProtocol}/${this.id}`;
this.dispatchNativeAutomationEventRelativeUrl = `${SERVICE_ROUTES.dispatchNativeAutomationEvent}/${this.id}`;
Expand Down Expand Up @@ -646,11 +648,19 @@ export default class BrowserConnection extends EventEmitter {
return this.provider.supportNativeAutomation();
}

public getNativeAutomation (): NativeAutomation {
public getNativeAutomation (): NativeAutomationBase {
return this.provider.getNativeAutomation(this.id);
}

public isNativeAutomationEnabled (): boolean {
return this._options.nativeAutomation;
}

async getNewWindowIdInNativeAutomation (windowId: string): Promise<void> {
return this.provider.getNewWindowIdInNativeAutomation(this.id, windowId);
}

public resetActiveWindowId (): void {
this.provider.resetActiveWindowId(this.id);
}
}
1 change: 1 addition & 0 deletions src/browser/connection/service-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
idle: '/browser/idle',
idleForced: '/browser/idle-forced',
activeWindowId: '/browser/active-window-id',
ensureWindowInNativeAutomation: '/browser/ensure-window-in-native-automation',
closeWindow: '/browser/close-window',
serviceWorker: '/service-worker.js',
openFileProtocol: '/browser/open-file-protocol',
Expand Down
8 changes: 6 additions & 2 deletions src/browser/provider/built-in/dedicated/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default {
return this.openedBrowsers[browserId].activeWindowId;
},

resetActiveWindowId (browserId) {
this.openedBrowsers[browserId].activeWindowId = this.openedBrowsers[browserId].nativeAutomation?.windowId;
},

setActiveWindowId (browserId, val) {
this.openedBrowsers[browserId].activeWindowId = val;
},
Expand Down Expand Up @@ -101,10 +105,10 @@ export default {
await this.resizeWindow(browserId, maximumSize.width, maximumSize.height, maximumSize.width, maximumSize.height);
},

async closeBrowserChildWindow (browserId) {
async closeBrowserChildWindow (browserId, windowId) {
const runtimeInfo = this.openedBrowsers[browserId];
const browserClient = this._getBrowserProtocolClient(runtimeInfo);

return browserClient.closeBrowserChildWindow();
return browserClient.closeBrowserChildWindow(windowId);
},
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export const CONTAINERIZED_CHROME_FLAGS = ['--no-sandbox', '--disable-dev-shm-usage'];

export function buildChromeArgs ({ config, cdpPort, platformArgs, tempProfileDir, isContainerized }) {
export function buildChromeArgs ({ config, cdpPort, platformArgs, tempProfileDir, isContainerized, isNativeAutomation }) {
let chromeArgs = []
.concat(
cdpPort ? [`--remote-debugging-port=${cdpPort}`] : [],
!config.userProfile ? [`--user-data-dir=${tempProfileDir.path}`] : [],
config.headless ? ['--headless'] : [],
config.userArgs ? [config.userArgs] : [],
// NOTE: we need to prevent new window blocking for multiple windows in Native Automation
isNativeAutomation ? ['--disable-popup-blocking'] : [],
platformArgs ? [platformArgs] : []
)
.join(' ');
Expand Down
Loading

0 comments on commit 4a08352

Please sign in to comment.