Skip to content

Commit

Permalink
Overhaul t.resizeWindow and implement t.maximizeWindow (closes DevExp…
Browse files Browse the repository at this point in the history
…ress#816, closes DevExpress#812) (DevExpress#837)

* Show error is the requested size is too big on Mac

* Implement t.maximize
  • Loading branch information
AndreyBelym authored and kirovboris committed Dec 18, 2019
1 parent 571d25f commit f33c166
Show file tree
Hide file tree
Showing 29 changed files with 525 additions and 254 deletions.
7 changes: 6 additions & 1 deletion src/api/test-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
import {
TakeScreenshotCommand,
ResizeWindowCommand,
ResizeWindowToFitDeviceCommand
ResizeWindowToFitDeviceCommand,
MaximizeWindowCommand
} from '../test-run/commands/browser-manipulation';

import { WaitCommand } from '../test-run/commands/observation';
Expand Down Expand Up @@ -205,6 +206,10 @@ export default class TestController {
return this._enqueueAction('resizeWindowToFitDevice', ResizeWindowToFitDeviceCommand, { device, options });
}

_maximizeWindow$ () {
return this._enqueueAction('maximizeWindow', MaximizeWindowCommand);
}

_switchToIframe$ (selector) {
return this._enqueueAction('switchToIframe', SwitchToIframeCommand, { selector });
}
Expand Down
109 changes: 0 additions & 109 deletions src/browser/provider/built-in/base.js

This file was deleted.

12 changes: 6 additions & 6 deletions src/browser/provider/built-in/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import PathBrowserProvider from './path';
import LocallyInstalledBrowserProvider from './locally-installed';
import RemoteBrowserProvider from './remote';
import pathBrowserProvider from './path';
import locallyInstalledBrowserProvider from './locally-installed';
import remoteBrowserProvider from './remote';


export default {
'locally-installed': new LocallyInstalledBrowserProvider(),
'path': new PathBrowserProvider(),
'remote': new RemoteBrowserProvider()
'locally-installed': locallyInstalledBrowserProvider,
'path': pathBrowserProvider,
'remote': remoteBrowserProvider
};
25 changes: 17 additions & 8 deletions src/browser/provider/built-in/locally-installed.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import browserTools from 'testcafe-browser-tools';
import PathBrowserProvider from './path';


export default class LocallyInstalledBrowserProvider extends PathBrowserProvider {
constructor () {
super();
export default {
isMultiBrowser: true,

this.isMultiBrowser = true;
}
async openBrowser (browserId, pageUrl, browserName) {
var openParameters = await browserTools.getBrowserInfo(browserName);

await browserTools.open(openParameters, pageUrl);
},

async closeBrowser (browserId) {
await browserTools.close(browserId);
},

async isLocalBrowser () {
return true;
},

async getBrowserList () {
var installations = await browserTools.getInstallations();

return Object.keys(installations);
}
},

async isValidBrowserName (browserName) {
var browserNames = await this.getBrowserList();
Expand All @@ -22,4 +31,4 @@ export default class LocallyInstalledBrowserProvider extends PathBrowserProvider

return browserNames.indexOf(browserName) > -1;
}
}
};
27 changes: 8 additions & 19 deletions src/browser/provider/built-in/path.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import browserTools from 'testcafe-browser-tools';
import OS from 'os-family';
import BrowserProviderBase from './base';


export default class PathBrowserProvider extends BrowserProviderBase {
constructor () {
super();

this.isMultiBrowser = true;
}
export default {
isMultiBrowser: true,

async _handleJSON (str) {
var params = null;
Expand All @@ -32,7 +26,7 @@ export default class PathBrowserProvider extends BrowserProviderBase {
openParameters.cmd = params.cmd;

return openParameters;
}
},

async openBrowser (browserId, pageUrl, browserName) {
var openParameters = await browserTools.getBrowserInfo(browserName) || await this._handleJSON(browserName);
Expand All @@ -41,18 +35,13 @@ export default class PathBrowserProvider extends BrowserProviderBase {
throw new Error('The specified browser name is not valid!');

await browserTools.open(openParameters, pageUrl);

if (OS.win)
await super.calculateResizeCorrections(browserId);
}
},

async closeBrowser (browserId) {
await browserTools.close(browserId);
}
},

async getBrowserList () {
return [
'${PATH_TO_BROWSER_EXECUTABLE}'
];
async isLocalBrowser () {
return true;
}
}
};
75 changes: 38 additions & 37 deletions src/browser/provider/built-in/remote.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
import BrowserProviderBase from './base';
import OS from 'os-family';
import { findWindow } from 'testcafe-browser-tools';
import WARNING_MESSAGE from '../../../warnings/message';


export default class RemoteBrowserProvider extends BrowserProviderBase {
constructor () {
super();

// NOTE: This can be used to disable resize correction when running unit tests.
this.disableResizeHack = false;
}
export default {
localBrowsersFlags: {},

async openBrowser (browserId) {
try {
if (OS.win && !this.disableResizeHack)
await super.calculateResizeCorrections(browserId);
}
catch (e) {
return;
}
}
await this.waitForConnectionReady(browserId);

async closeBrowser () {
return;
}
var localBrowserWindow = await findWindow(browserId);

// NOTE: we must try to do a local screenshot or resize, if browser is accessible, but emit warning
async takeScreenshot (browserId, ...args) {
try {
await super.takeScreenshot(browserId, ...args);
}
catch (e) {
this.reportWarning(browserId, WARNING_MESSAGE.browserManipulationsOnRemoteBrowser);
}
}
this.localBrowsersFlags[browserId] = localBrowserWindow !== null;
},

async closeBrowser (browserId) {
delete this.localBrowsersFlags[browserId];
},

async isLocalBrowser (browserId) {
return this.localBrowsersFlags[browserId];
},

// NOTE: we must try to do a local screenshot or resize, if browser is accessible, and emit warning otherwise
async hasCustomActionForBrowser (browserId) {
var isLocalBrowser = this.localBrowsersFlags[browserId];

return {
hasResizeWindow: !isLocalBrowser,
hasMaximizeWindow: !isLocalBrowser,
hasTakeScreenshot: !isLocalBrowser,
hasCanResizeWindowToDimensions: !isLocalBrowser
};
},

async takeScreenshot (browserId) {
this.reportWarning(browserId, WARNING_MESSAGE.browserManipulationsOnRemoteBrowser);
},

async resizeWindow (browserId) {
this.reportWarning(browserId, WARNING_MESSAGE.browserManipulationsOnRemoteBrowser);
},

async resizeWindow (browserId, ...args) {
try {
await super.resizeWindow(browserId, ...args);
}
catch (e) {
this.reportWarning(browserId, WARNING_MESSAGE.browserManipulationsOnRemoteBrowser);
}
async maximizeWindow (browserId) {
this.reportWarning(browserId, WARNING_MESSAGE.browserManipulationsOnRemoteBrowser);
}
}
};
27 changes: 0 additions & 27 deletions src/browser/provider/cache-item.js

This file was deleted.

Loading

0 comments on commit f33c166

Please sign in to comment.