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 12, 2015
1 parent 36ead6b commit 7614dbd
Show file tree
Hide file tree
Showing 33 changed files with 619 additions and 557 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
26 changes: 13 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 @@ -13,26 +16,23 @@ export var batchUpdate = transport.batchUpdate.bind(transpor
export var queuedAsyncServiceMsg = transport.queuedAsyncServiceMsg.bind(transport);

export function fail (err, callback) {
// NOTE: we should not stop the test run if an error occured during page unloading because
// we destroy the session in this case and we can't get the next page in the browser.
// We should set the deferred error to the task to fail the test 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
5 changes: 2 additions & 3 deletions src/client/runner/iframe-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,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 @@ -116,7 +114,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 () {
type: 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 @@ -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 @@ -377,7 +382,7 @@ RunnerBase.prototype._runInIFrame = function (iframe, stepName, step, stepNum) {
if (err) {
runner._onError({
type: ERROR_TYPE.inIFrameTargetLoadingTimeout,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: runner.stepIterator.getCurrentStep()
});
}
else {
Expand All @@ -391,7 +396,7 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
if (!arg) {
this._onError({
type: ERROR_TYPE.emptyIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -402,7 +407,7 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
else {
this._onError({
type: ERROR_TYPE.iframeArgumentIsNotIFrame,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -415,14 +420,14 @@ RunnerBase.prototype._ensureIFrame = function (arg) {
if (arg.length === 0) {
this._onError({
type: ERROR_TYPE.emptyIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
else if (arg.length > 1) {
this._onError({
type: ERROR_TYPE.multipleIFrameArgument,
stepName: SETTINGS.get().CURRENT_TEST_STEP_NAME
stepName: this.stepIterator.getCurrentStep()
});
return null;
}
Expand All @@ -435,8 +440,9 @@ RunnerBase.prototype._ensureIFrame = function (arg) {

this._onError({
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
Loading

0 comments on commit 7614dbd

Please sign in to comment.