Skip to content

Commit

Permalink
Enable screenshot functionality (closes DevExpress#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderMoskovkin authored and VasilyStrelyaev committed Jan 14, 2016
1 parent aba4ace commit 84e8fde
Show file tree
Hide file tree
Showing 39 changed files with 688 additions and 624 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"testcafe-browser-natives": "^0.10.0",
"testcafe-hammerhead": "^0.2.1",
"uglify-js": "1.2.6",
"useragent": "^2.1.7"
"useragent": "^2.1.7",
"uuid": "^2.0.1"
},
"devDependencies": {
"babel": "^5.8.23",
Expand Down
28 changes: 14 additions & 14 deletions src/client/core/transport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import hammerhead from './deps/hammerhead';
import COMMAND from '../../runner/test-run/command';

var transport = hammerhead.transport;
var transport = hammerhead.transport;
var beforeUnloadRaised = false;

hammerhead.on(hammerhead.EVENTS.beforeUnload, () => beforeUnloadRaised = true);


//Exports
Expand All @@ -12,27 +15,24 @@ export var waitForServiceMessagesCompleted = transport.waitForServiceMessagesCom
export var batchUpdate = transport.batchUpdate.bind(transport);
export var queuedAsyncServiceMsg = transport.queuedAsyncServiceMsg.bind(transport);

export function fail (err, callback) {
export function fatalError (err, callback) {
// NOTE: we should not stop the test run if an error occured during page unloading because we
// would destroy the session in this case and wouldn't be able to get the next page in the browser.
// We should set the deferred error to the task to have the test fail after the page reloading.
var testFailMsg = {
cmd: COMMAND.fatalError,
err: err
cmd: COMMAND.fatalError,
err: err,
deferred: beforeUnloadRaised
};

transport.asyncServiceMsg(testFailMsg, function () {
callback();
});

//HACK: this helps stop current JS context execution
window.onerror = function () {
};
throw 'STOP';
transport.asyncServiceMsg(testFailMsg, callback);
}

export function assertionFailed (err) {
export function assertionFailed (err, callback) {
var assertionFailedMsg = {
cmd: COMMAND.assertionFailed,
err: err
};

transport.asyncServiceMsg(assertionFailedMsg);
transport.asyncServiceMsg(assertionFailedMsg, callback);
}
4 changes: 2 additions & 2 deletions src/client/runner/api/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,11 @@ export function upload (what, path) {
);
}

export function screenshot () {
export function screenshot (filePath) {
stepIterator.asyncAction(function (iteratorCallback) {
stepIterator.takeScreenshot(function () {
iteratorCallback();
}, false);
}, filePath);
});
}

Expand Down
10 changes: 4 additions & 6 deletions src/client/runner/iframe-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ IFrameRunner.prototype._onActionRun = function () {
messageSandbox.sendServiceMsg({ cmd: RunnerBase.IFRAME_ACTION_RUN_CMD }, window.top);
};

IFrameRunner.prototype._onError = function (err) {

IFrameRunner.prototype._onFatalError = function (err) {
if (!SETTINGS.get().PLAYBACK || err.dialog)
this.stepIterator.stop();

Expand All @@ -78,8 +77,6 @@ IFrameRunner.prototype._onAssertionFailed = function (e) {
err: e
};

this.stepIterator.state.needScreeshot = true;

messageSandbox.sendServiceMsg(msg, window.top);

if (SETTINGS.get().PLAYBACK)
Expand Down Expand Up @@ -115,8 +112,9 @@ IFrameRunner.prototype._onGetStepsSharedData = function (e) {

IFrameRunner.prototype._onTakeScreenshot = function (e) {
var msg = {
cmd: RunnerBase.IFRAME_TAKE_SCREENSHOT_REQUEST_CMD,
isFailedStep: e.isFailedStep
cmd: RunnerBase.IFRAME_TAKE_SCREENSHOT_REQUEST_CMD,
stepName: e.stepName,
filePath: e.filePath
};

messageSandbox.sendServiceMsg(msg, window.top);
Expand Down
50 changes: 28 additions & 22 deletions src/client/runner/runner-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,22 @@ var RunnerBase = function () {
if (err.inIFrame && !SETTINGS.get().PLAYBACK)
runner.stepIterator.stop();
else if (!SETTINGS.get().SKIP_JS_ERRORS || SETTINGS.get().RECORDING) {
runner._onError({
runner._onFatalError({
type: ERROR_TYPE.uncaughtJSError,
scriptErr: err.msg,
pageError: true,
pageUrl: err.pageUrl
pageUrl: err.pageUrl,
stepName: runner.stepIterator.getCurrentStep()
});
}
});

runner.stepIterator.on(StepIterator.ERROR_EVENT, function (e) {
runner._onError(e);
runner._onFatalError(e);
});

runner.act._onJSError = function (err) {
runner._onError({
runner._onFatalError({
type: ERROR_TYPE.uncaughtJSError,
scriptErr: (err && err.message) || err
});
Expand All @@ -105,6 +106,9 @@ var RunnerBase = function () {
//NOTE: start test execution only when all content is loaded or if loading
//timeout is reached (whichever comes first).
runner._prepareStepsExecuting(function () {
if (runner.stopped)
return;

delete runner.act._onJSError;
delete runner.act._start;

Expand Down Expand Up @@ -203,15 +207,15 @@ RunnerBase.prototype._initIFrameBehavior = function () {
message.err.stepName = runner.stepIterator.getCurrentStep();
}
runner._clearIFrameExistenceWatcherInterval();
runner._onError(message.err);
runner._onFatalError(message.err);
break;

case RunnerBase.IFRAME_FAILED_ASSERTION_CMD:
if (SETTINGS.get().PLAYBACK)
runner.executingStepInIFrameWindow = null;

message.err.stepNum = runner.stepIterator.state.step - 1;
runner._onAssertionFailed(message.err, true);
runner._onAssertionFailed(message.err);
break;

case RunnerBase.IFRAME_GET_SHARED_DATA_REQUEST_CMD:
Expand Down Expand Up @@ -256,8 +260,9 @@ RunnerBase.prototype._initIFrameBehavior = function () {

case RunnerBase.IFRAME_TAKE_SCREENSHOT_REQUEST_CMD:
runner._onTakeScreenshot({
isFailedStep: message.isFailedStep,
callback: function () {
stepName: message.stepName,
filePath: message.filePath,
callback: function () {
msg = {
cmd: RunnerBase.IFRAME_TAKE_SCREENSHOT_RESPONSE_CMD
};
Expand Down Expand Up @@ -375,9 +380,9 @@ RunnerBase.prototype._runInIFrame = function (iframe, stepName, step, stepNum) {

pingIFrame(iframe, function (err) {
if (err) {
runner._onError({
runner._onFatalError({
type: ERROR_TYPE.inIFrameTargetLoadingTimeout,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: runner.stepIterator.getCurrentStep()
});
}
else {
Expand All @@ -389,9 +394,9 @@ RunnerBase.prototype._runInIFrame = function (iframe, stepName, step, stepNum) {

RunnerBase.prototype._ensureIFrame = function (arg) {
if (!arg) {
this._onError({
this._onFatalError({
type: ERROR_TYPE.emptyIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -400,9 +405,9 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
if (arg.tagName && arg.tagName.toLowerCase() === 'iframe')
return arg;
else {
this._onError({
this._onFatalError({
type: ERROR_TYPE.iframeArgumentIsNotIFrame,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -413,16 +418,16 @@ RunnerBase.prototype._ensureIFrame = function (arg) {

if (serviceUtils.isJQueryObj(arg)) {
if (arg.length === 0) {
this._onError({
this._onFatalError({
type: ERROR_TYPE.emptyIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
else if (arg.length > 1) {
this._onError({
this._onFatalError({
type: ERROR_TYPE.multipleIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -433,10 +438,11 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
if (typeof arg === 'function')
return this._ensureIFrame(arg());

this._onError({
this._onFatalError({
type: ERROR_TYPE.incorrectIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});

return null;
};

Expand Down Expand Up @@ -468,7 +474,7 @@ RunnerBase.prototype._initApi = function () {
iFrame = runner._ensureIFrame(iFrameGetter());

if (iFrame)
runner._runInIFrame(iFrame, SETTINGS.get().CURRENT_TEST_STEP_NAME, step, stepNum);
runner._runInIFrame(iFrame, runner.stepIterator.getCurrentStep(), step, stepNum);
};
};
};
Expand Down Expand Up @@ -526,7 +532,7 @@ RunnerBase.prototype._onActionRun = function () {
this.eventEmitter.emit(this.ACTION_RUN_EVENT, {});
};

RunnerBase.prototype._onError = function (err) {
RunnerBase.prototype._onFatalError = function (err) {
this.eventEmitter.emit(this.TEST_FAILED_EVENT, {
stepNum: this.stepIterator.state.step - 1,
err: err
Expand Down
Loading

0 comments on commit 84e8fde

Please sign in to comment.