Skip to content

Commit

Permalink
fix: resizi and maximize window in beforeEach fixture hook
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelMor25 committed Feb 12, 2024
1 parent 876db34 commit 01e19ae
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/browser/provider/built-in/dedicated/chrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions test/functional/fixtures/regression/gh-8117/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Resize window</title>
</head>
<body>
</body>
</html>
47 changes: 47 additions & 0 deletions test/functional/fixtures/regression/gh-8117/test.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 01e19ae

Please sign in to comment.