Skip to content

Commit d4dfcb3

Browse files
committed
fix: resizi and maximize window in beforeEach fixture hook
1 parent 876db34 commit d4dfcb3

File tree

6 files changed

+98
-2
lines changed

6 files changed

+98
-2
lines changed

gulp/constants/functional-test-globs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const MULTIPLE_WINDOWS_TESTS_GLOB = 'test/functional/fixtures/multiple-windows/test.js';
1+
const MULTIPLE_WINDOWS_TESTS_GLOB = ['test/functional/fixtures/multiple-windows/test.js', 'test/functional/fixtures/regression/gh-8117/test.js'];
22
const HEADED_CHROME_FIREFOX_TESTS_GLOB = ['test/functional/fixtures/live/test.js', 'test/functional/fixtures/ui/test.js'];
33
const COMPILER_SERVICE_TESTS_GLOB = 'test/functional/fixtures/compiler-service/test.js';
44
const LEGACY_TESTS_GLOB = 'test/functional/legacy-fixtures/**/test.js';

src/browser/provider/built-in/dedicated/chrome/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default {
9797
if (additionalOptions.nativeAutomation)
9898
await this._setupNativeAutomation({ browserId, browserClient, runtimeInfo, nativeAutomationOptions: toNativeAutomationSetupOptions(additionalOptions, config.headless) });
9999

100-
if (!additionalOptions.disableMultipleWindows)
100+
if (!additionalOptions.disableMultipleWindows || additionalOptions.nativeAutomation)
101101
runtimeInfo.activeWindowId = runtimeInfo?.nativeAutomation?.windowId || this.calculateWindowId();
102102

103103
await browserClient.initMainWindowCdpClient();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Resize window</title>
6+
</head>
7+
<body>
8+
</body>
9+
</html>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { onlyInNativeAutomation } = require('../../../utils/skip-in');
2+
const path = require('path');
3+
const createTestCafe = require('../../../../../lib');
4+
const { createReporter } = require('../../../utils/reporter');
5+
const { expect } = require('chai');
6+
7+
let testCafe = null;
8+
let runner = null;
9+
let errors = null;
10+
11+
const reporter = createReporter({
12+
reportTestDone (_, testRunInfo) {
13+
errors = testRunInfo.errs;
14+
},
15+
});
16+
17+
const run = (pathToTest, concurrency) => {
18+
const src = path.join(__dirname, pathToTest);
19+
20+
return createTestCafe('127.0.0.1', 1335, 1336)
21+
.then(tc => {
22+
testCafe = tc;
23+
})
24+
.then(() => {
25+
runner = testCafe.createRunner();
26+
return runner
27+
.src(src)
28+
.browsers(`chrome`)
29+
.reporter(reporter)
30+
.concurrency(concurrency)
31+
.run({ disableMultipleWindows: true });
32+
})
33+
.then(() => {
34+
testCafe.close();
35+
});
36+
};
37+
38+
describe('[Regression](GH-8117)', function () {
39+
onlyInNativeAutomation('Should resize and maximize window in native automation mode with disableMultipleWindows option', function () {
40+
return run('testcafe-fixtures/maximize.js')
41+
.then(() => expect(errors.length).eql(0));
42+
});
43+
onlyInNativeAutomation('Should resize window in native automation mode with disableMultipleWindows option', function () {
44+
return run('testcafe-fixtures/resize.js')
45+
.then(() => expect(errors.length).eql(0));
46+
});
47+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect } from 'chai';
2+
import { ClientFunction } from 'testcafe';
3+
4+
const getWindowDimensionsInfo = ClientFunction(() => {
5+
return {
6+
innerWidth: window.innerWidth,
7+
innerHeight: window.innerHeight,
8+
outerWidth: window.outerWidth,
9+
outerHeight: window.outerHeight,
10+
availableHeight: screen.availHeight,
11+
availableWidth: screen.availWidth,
12+
};
13+
});
14+
15+
fixture `Maximize Window`
16+
.page `http://localhost:3000/fixtures/regression/gh-8117/pages/index.html`;
17+
18+
test('Maximize window', async t => {
19+
await t.maximizeWindow();
20+
21+
const dimensions = await getWindowDimensionsInfo();
22+
23+
expect(dimensions.outerWidth).to.be.at.least(dimensions.availableWidth);
24+
expect(dimensions.outerHeight).to.be.at.least(dimensions.availableHeight);
25+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect } from 'chai';
2+
import { getWindowHeight, getWindowWidth } from '../../../../esm-utils/window-helpers.js';
3+
4+
fixture `Resize window`
5+
.page `http://localhost:3000/fixtures/regression/gh-8117/pages/index.html`;
6+
7+
test('Resize window', async t => {
8+
const newWidth = 500;
9+
const newHeight = 500;
10+
11+
await t.resizeWindow(newWidth, newHeight);
12+
13+
expect(await getWindowWidth()).equals(newWidth);
14+
expect(await getWindowHeight()).equals(newHeight);
15+
});

0 commit comments

Comments
 (0)