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 committed Nov 10, 2015
1 parent 28731c1 commit f7ba663
Show file tree
Hide file tree
Showing 30 changed files with 562 additions and 564 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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
23 changes: 10 additions & 13 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 @@ -14,25 +17,19 @@ export var queuedAsyncServiceMsg = transport.queuedAsyncServiceMsg.bin

export function fail (err, callback) {
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
5 changes: 2 additions & 3 deletions src/client/runner/iframe-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,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 @@ -111,7 +109,8 @@ IFrameRunner.prototype._onGetStepsSharedData = function (e) {
IFrameRunner.prototype._onTakeScreenshot = function (e) {
var msg = {
cmd: RunnerBase.IFRAME_TAKE_SCREENSHOT_REQUEST_CMD,
isFailedStep: e.isFailedStep
stepName: e.stepName,
filePath: e.filePath
};

messageSandbox.sendServiceMsg(msg, window.top);
Expand Down
28 changes: 17 additions & 11 deletions src/client/runner/runner-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ var RunnerBase = function () {
code: ERROR_TYPE.uncaughtJSError,
scriptErr: err.msg,
pageError: true,
pageUrl: err.pageUrl
pageUrl: err.pageUrl,
stepName: runner.stepIterator.getCurrentStep()
});
}
});
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 @@ -211,7 +215,7 @@ RunnerBase.prototype._initIFrameBehavior = function () {
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 @@ -254,8 +258,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,7 +380,7 @@ RunnerBase.prototype._runInIFrame = function (iframe, stepName, step, stepNum) {
if (err) {
runner._onError({
code: ERROR_TYPE.inIFrameTargetLoadingTimeout,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: runner.stepIterator.getCurrentStep()
});
}
else {
Expand All @@ -389,7 +394,7 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
if (!arg) {
this._onError({
code: ERROR_TYPE.emptyIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -400,7 +405,7 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
else {
this._onError({
code: ERROR_TYPE.iframeArgumentIsNotIFrame,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -413,14 +418,14 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
if (arg.length === 0) {
this._onError({
code: ERROR_TYPE.emptyIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
else if (arg.length > 1) {
this._onError({
code: ERROR_TYPE.multipleIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -433,8 +438,9 @@ RunnerBase.prototype._ensureIFrame = function (arg) {

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

return null;
};

Expand Down Expand Up @@ -466,7 +472,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
Loading

0 comments on commit f7ba663

Please sign in to comment.