Skip to content

Commit

Permalink
fix: resize and maximize window with disableMultipleWindows option …
Browse files Browse the repository at this point in the history
…in NA mode (#8135)

<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->

## Purpose


## Approach


## References
closes #8117 

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail
  • Loading branch information
PavelMor25 authored Feb 16, 2024
1 parent 876db34 commit 93b3ccb
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ testingEnvironments[testingEnvironmentNames.mobileBrowsers] = {

browsers: [
{
browserName: 'browserstack:iPad 9th@15',
browserName: 'browserstack:ipad:ios 15',
alias: 'ipad',
},
{
browserName: 'browserstack:iPhone 13 Pro@15',
browserName: 'browserstack:iphone:ios 15',
alias: 'iphone',
},
],
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 93b3ccb

Please sign in to comment.