Skip to content

Commit

Permalink
Stabilize screenshot tests, Update testcafe-browser-tools (DevExpress…
Browse files Browse the repository at this point in the history
…#1691)

Improve browser manipulations mechanism. Update testcafe-browser-tools (fixes DevExpress#1732, fixes DevExpress#1551)
  • Loading branch information
AlexanderMoskovkin authored and kirovboris committed Dec 18, 2019
1 parent 3b8b6e2 commit d6501e9
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"source-map-support": "^0.4.0",
"stack-chain": "^1.3.6",
"strip-bom": "^2.0.0",
"testcafe-browser-tools": "1.4.1",
"testcafe-browser-tools": "1.4.3",
"testcafe-hammerhead": "11.1.1",
"testcafe-legacy-api": "3.1.1",
"testcafe-reporter-json": "^2.1.0",
Expand Down
13 changes: 9 additions & 4 deletions src/browser/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class BrowserProvider {
// we are resizing it for the first time to switch the window to normal mode, and for the second time - to restore the client area size.
this.resizeCorrections = {};
this.maxScreenSizes = {};
this.windowDescriptors = {};
}

async _calculateResizeCorrections (browserId) {
Expand Down Expand Up @@ -101,14 +102,18 @@ export default class BrowserProvider {
}

async _onOpenBrowser (browserId) {
this.windowDescriptors[browserId] = await browserTools.findWindow(browserId);

if (OS.win)
await this._calculateResizeCorrections(browserId);
else if (OS.mac)
await this._calculateMacSizeLimits(browserId);
}

async _closeLocalBrowser (browserId) {
await browserTools.close(browserId);
await browserTools.close(this.windowDescriptors[browserId]);

delete this.windowDescriptors[browserId];
}

async _resizeLocalBrowserWindow (browserId, width, height, currentWidth, currentHeight) {
Expand All @@ -119,11 +124,11 @@ export default class BrowserProvider {
delete this.resizeCorrections[browserId];
}

await browserTools.resize(browserId, currentWidth, currentHeight, width, height);
await browserTools.resize(this.windowDescriptors[browserId], currentWidth, currentHeight, width, height);
}

async _takeLocalBrowserScreenshot (browserId, screenshotPath) {
await browserTools.screenshot(browserId, screenshotPath);
await browserTools.screenshot(this.windowDescriptors[browserId], screenshotPath);
}

async _canResizeLocalBrowserWindowToDimensions (browserId, width, height) {
Expand All @@ -136,7 +141,7 @@ export default class BrowserProvider {
}

async _maximizeLocalBrowserWindow (browserId) {
await browserTools.maximize(browserId);
await browserTools.maximize(this.windowDescriptors[browserId]);
}

async init () {
Expand Down
53 changes: 14 additions & 39 deletions src/client/driver/command-executors/prepare-browser-manipulation.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,32 @@
import hammerhead from '../deps/hammerhead';
import testCafeCore from '../deps/testcafe-core';
import { transport } from '../deps/hammerhead';
import { delay } from '../deps/testcafe-core';
import { hide as hideUI, show as showUI } from '../deps/testcafe-ui';
import MESSAGE from '../../../test-run/client-messages';
import DriverStatus from '../status';


var nativeMethods = hammerhead.nativeMethods;
var transport = hammerhead.transport;
var delay = testCafeCore.delay;
const POSSIBLE_RESIZE_ERROR_DELAY = 100;

const CHECK_TITLE_INTERVAL = 50;
const APPLY_DOCUMENT_TITLE_TIMEOUT = 500;
const RESTORE_DOCUMENT_TITLE_TIMEOUT = 100;
export default function prepareBrowserManipulation () {
var result = null;


export default function prepareBrowserManipulation (browserId) {
var savedDocumentTitle = document.title;
var assignedTitle = `[ ${browserId} ]`;
var checkTitleIntervalId = null;
var result = null;

// NOTE: we should keep the page url in document.title
// while the browser manipulation is in progress.
checkTitleIntervalId = nativeMethods.setInterval.call(window, () => {
if (document.title !== assignedTitle) {
savedDocumentTitle = document.title;
document.title = assignedTitle;
}
}, CHECK_TITLE_INTERVAL);

document.title = assignedTitle;
var message = {
cmd: MESSAGE.readyForBrowserManipulation,
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
disableResending: true
};

hideUI();

return delay(APPLY_DOCUMENT_TITLE_TIMEOUT)
.then(() => {
var message = {
cmd: MESSAGE.readyForBrowserManipulation,
innerWidth: window.innerWidth,
innerHeight: window.innerHeight,
disableResending: true
};

return transport.queuedAsyncServiceMsg(message);
})
return transport
.queuedAsyncServiceMsg(message)
.then(res => {
result = res;
nativeMethods.clearInterval.call(window, checkTitleIntervalId);
document.title = savedDocumentTitle;

showUI();

return delay(RESTORE_DOCUMENT_TITLE_TIMEOUT);
return delay(POSSIBLE_RESIZE_ERROR_DELAY);
})
.then(() => new DriverStatus({ isCommandResult: true, result }));
}
7 changes: 3 additions & 4 deletions src/client/driver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@ const CURRENT_IFRAME_ERROR_CTORS = {


export default class Driver {
constructor (ids, communicationUrls, runInfo, options) {
constructor (testRunId, communicationUrls, runInfo, options) {
this.COMMAND_EXECUTING_FLAG = 'testcafe|driver|command-executing-flag';
this.EXECUTING_IN_IFRAME_FLAG = 'testcafe|driver|executing-in-iframe-flag';

this.testRunId = ids.testRun;
this.browserId = ids.browser;
this.testRunId = testRunId;
this.heartbeatUrl = communicationUrls.heartbeat;
this.browserStatusUrl = communicationUrls.status;
this.userAgent = runInfo.userAgent;
Expand Down Expand Up @@ -379,7 +378,7 @@ export default class Driver {
_onPrepareBrowserManipulationCommand () {
this.contextStorage.setItem(this.COMMAND_EXECUTING_FLAG, true);

prepareBrowserManipulation(this.browserId)
prepareBrowserManipulation()
.then(driverStatus => {
this.contextStorage.setItem(this.COMMAND_EXECUTING_FLAG, false);
return this._onReady(driverStatus);
Expand Down
4 changes: 2 additions & 2 deletions src/client/driver/iframe-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import IframeNativeDialogTracker from './native-dialog-tracker/iframe';


export default class IframeDriver extends Driver {
constructor (ids, options) {
super(ids, {}, {}, options);
constructor (testRunId, options) {
super(testRunId, {}, {}, options);

this.lastParentDriverMessageId = null;
this.parentDriverLink = new ParentDriverLink(window.parent);
Expand Down
2 changes: 1 addition & 1 deletion src/client/test-run/iframe.js.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {
var IframeDriver = window['%testCafeIframeDriver%'];
var driver = new IframeDriver({ testRun: {{{testRunId}}} }, {
var driver = new IframeDriver({{{testRunId}}}, {
selectorTimeout: {{{selectorTimeout}}},
dialogHandler: {{{dialogHandler}}},
speed: {{{speed}}}
Expand Down
3 changes: 1 addition & 2 deletions src/client/test-run/index.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
var testName = {{{testName}}};

var ClientDriver = window['%testCafeDriver%'];
var driver = new ClientDriver(
{ testRun: testRunId, browser: browserId },
var driver = new ClientDriver(testRunId,
{ heartbeat: browserHeartbeatUrl, status: browserStatusUrl },
{ userAgent: userAgent, fixtureName: fixtureName, testName: testName },
{
Expand Down

0 comments on commit d6501e9

Please sign in to comment.