diff --git a/gulp/constants/functional-test-globs.js b/gulp/constants/functional-test-globs.js index b41c49e6932..19c207ef330 100644 --- a/gulp/constants/functional-test-globs.js +++ b/gulp/constants/functional-test-globs.js @@ -1,4 +1,4 @@ -const MULTIPLE_WINDOWS_TESTS_GLOB = 'test/functional/fixtures/multiple-windows/test.js'; +const MULTIPLE_WINDOWS_TESTS_GLOB = ['test/functional/fixtures/multiple-windows/test.js', 'test/functional/fixtures/regression/gh-8117/test.js']; const HEADED_CHROME_FIREFOX_TESTS_GLOB = ['test/functional/fixtures/live/test.js', 'test/functional/fixtures/ui/test.js']; const COMPILER_SERVICE_TESTS_GLOB = 'test/functional/fixtures/compiler-service/test.js'; const LEGACY_TESTS_GLOB = 'test/functional/legacy-fixtures/**/test.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..cef8137072b 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.disableMultipleWindows || additionalOptions.nativeAutomation) 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); +});