From 01e19ae118d7cde0b9d5df0103ff5ddc1ace5ff4 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 12 Feb 2024 10:51:03 +0400 Subject: [PATCH] fix: resizi and maximize window in beforeEach fixture hook --- .../built-in/dedicated/chrome/index.js | 2 +- .../regression/gh-8117/pages/index.html | 9 ++++ .../fixtures/regression/gh-8117/test.js | 47 +++++++++++++++++++ .../gh-8117/testcafe-fixtures/maximize.js | 25 ++++++++++ .../gh-8117/testcafe-fixtures/resize.js | 15 ++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/functional/fixtures/regression/gh-8117/pages/index.html create mode 100644 test/functional/fixtures/regression/gh-8117/test.js create mode 100644 test/functional/fixtures/regression/gh-8117/testcafe-fixtures/maximize.js create mode 100644 test/functional/fixtures/regression/gh-8117/testcafe-fixtures/resize.js diff --git a/src/browser/provider/built-in/dedicated/chrome/index.js b/src/browser/provider/built-in/dedicated/chrome/index.js index b64cd60e7ba..57920cdf045 100644 --- a/src/browser/provider/built-in/dedicated/chrome/index.js +++ b/src/browser/provider/built-in/dedicated/chrome/index.js @@ -97,7 +97,7 @@ export default { if (additionalOptions.nativeAutomation) await this._setupNativeAutomation({ browserId, browserClient, runtimeInfo, nativeAutomationOptions: toNativeAutomationSetupOptions(additionalOptions, config.headless) }); - if (!additionalOptions.disableMultipleWindows) + if (additionalOptions.nativeAutomation || !additionalOptions.disableMultipleWindows) runtimeInfo.activeWindowId = runtimeInfo?.nativeAutomation?.windowId || this.calculateWindowId(); await browserClient.initMainWindowCdpClient(); diff --git a/test/functional/fixtures/regression/gh-8117/pages/index.html b/test/functional/fixtures/regression/gh-8117/pages/index.html new file mode 100644 index 00000000000..cd68eacf39c --- /dev/null +++ b/test/functional/fixtures/regression/gh-8117/pages/index.html @@ -0,0 +1,9 @@ + + + + + Resize window + + + + diff --git a/test/functional/fixtures/regression/gh-8117/test.js b/test/functional/fixtures/regression/gh-8117/test.js new file mode 100644 index 00000000000..15f4f1b7484 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8117/test.js @@ -0,0 +1,47 @@ +const { onlyInNativeAutomation } = require('../../../utils/skip-in'); +const path = require('path'); +const createTestCafe = require('../../../../../lib'); +const { createReporter } = require('../../../utils/reporter'); +const { expect } = require('chai'); + +let testCafe = null; +let runner = null; +let errors = null; + +const reporter = createReporter({ + reportTestDone (_, testRunInfo) { + errors = testRunInfo.errs; + }, +}); + +const run = (pathToTest, concurrency) => { + const src = path.join(__dirname, pathToTest); + + return createTestCafe('127.0.0.1', 1335, 1336) + .then(tc => { + testCafe = tc; + }) + .then(() => { + runner = testCafe.createRunner(); + return runner + .src(src) + .browsers(`chrome`) + .reporter(reporter) + .concurrency(concurrency) + .run({ disableMultipleWindows: true }); + }) + .then(() => { + testCafe.close(); + }); +}; + +describe('[Regression](GH-8117)', function () { + onlyInNativeAutomation('Should resize and maximize window in native automation mode with disableMultipleWindows option', function () { + return run('testcafe-fixtures/maximize.js') + .then(() => expect(errors.length).eql(0)); + }); + onlyInNativeAutomation('Should resize window in native automation mode with disableMultipleWindows option', function () { + return run('testcafe-fixtures/resize.js') + .then(() => expect(errors.length).eql(0)); + }); +}); diff --git a/test/functional/fixtures/regression/gh-8117/testcafe-fixtures/maximize.js b/test/functional/fixtures/regression/gh-8117/testcafe-fixtures/maximize.js new file mode 100644 index 00000000000..adaed2a884c --- /dev/null +++ b/test/functional/fixtures/regression/gh-8117/testcafe-fixtures/maximize.js @@ -0,0 +1,25 @@ +import { expect } from 'chai'; +import { ClientFunction } from 'testcafe'; + +const getWindowDimensionsInfo = ClientFunction(() => { + return { + innerWidth: window.innerWidth, + innerHeight: window.innerHeight, + outerWidth: window.outerWidth, + outerHeight: window.outerHeight, + availableHeight: screen.availHeight, + availableWidth: screen.availWidth, + }; +}); + +fixture `Maximize Window` + .page `http://localhost:3000/fixtures/regression/gh-8117/pages/index.html`; + +test('Maximize window', async t => { + await t.maximizeWindow(); + + const dimensions = await getWindowDimensionsInfo(); + + expect(dimensions.outerWidth).to.be.at.least(dimensions.availableWidth); + expect(dimensions.outerHeight).to.be.at.least(dimensions.availableHeight); +}); diff --git a/test/functional/fixtures/regression/gh-8117/testcafe-fixtures/resize.js b/test/functional/fixtures/regression/gh-8117/testcafe-fixtures/resize.js new file mode 100644 index 00000000000..951f1aaab02 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8117/testcafe-fixtures/resize.js @@ -0,0 +1,15 @@ +import { expect } from 'chai'; +import { getWindowHeight, getWindowWidth } from '../../../../esm-utils/window-helpers.js'; + +fixture `Resize window` + .page `http://localhost:3000/fixtures/regression/gh-8117/pages/index.html`; + +test('Resize window', async t => { + const newWidth = 500; + const newHeight = 500; + + await t.resizeWindow(newWidth, newHeight); + + expect(await getWindowWidth()).equals(newWidth); + expect(await getWindowHeight()).equals(newHeight); +});