Skip to content

Commit

Permalink
javascript wrapper for command line runner added. Provided API to reg…
Browse files Browse the repository at this point in the history
…ister wrapper within global object and assertionHelper
  • Loading branch information
ap4y authored and alexvollmer committed Mar 12, 2013
1 parent 54436dc commit 71ae6a7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
70 changes: 70 additions & 0 deletions image_assertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
var ImageAsserter = (function() {

function ImageAsserter(tuneUpPath, outputPath, refImagesPath) {

if (!outputPath || !refImagesPath || !tuneUpPath) {

throw new AssertionException("output, refImages, tuneUp pathes can't be null");
}

this.tuneUpPath = tuneUpPath;
this.outputPath = outputPath;
this.refImagesPath = refImagesPath;

var target = UIATarget.localTarget();
if (!target) {

throw new AssertionException("unable to get localTarget");
}

this.host = target.host();
if (!this.host) {

throw new AssertionException("unable to get current UAIHost");
}
}

ImageAsserter.prototype.assertImageNamed = function(imageName) {

var command,
taskResult,
assertSuccessfull = false,
SUCCESS_EXIT_CODE = 0,
TIMEOUT = 5,
args = [this.outputPath, this.refImagesPath, imageName];

command = this.tuneUpPath + '/image_asserter';
taskResult = this.host.performTaskWithPathArgumentsTimeout(command,
args,
TIMEOUT);

assertSuccessfull = (taskResult.exitCode === SUCCESS_EXIT_CODE);
if (!assertSuccessfull) UIALogger.logError(taskResult.stderr);

return assertSuccessfull;
};

return ImageAsserter;
}());

function createImageAsserter(tuneUpPath, outputPath, refImagesPath) {

this.imageAsserter = new ImageAsserter(tuneUpPath, outputPath, refImagesPath);
}

function assertScreenMatchesImageNamed(imageName, message) {

if (!this.imageAsserter) {
throw new AssertionException("imageAsserter isn't created.");
}

UIATarget.localTarget().captureAppScreenWithName(imageName);
UIATarget.localTarget().delay(1); // delay for screenshot to be saved

var assertionPassed = this.imageAsserter.assertImageNamed(imageName);
if (!assertionPassed) {

if (!message) message = 'Assertion of the image ' + imageName + ' failed.';
throw new AssertionException(message);
}
}
1 change: 1 addition & 0 deletions tuneup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#import "uiautomation-ext.js"
#import "screen.js"
#import "test.js"
#import "image_assertion.js"

0 comments on commit 71ae6a7

Please sign in to comment.