Skip to content

Commit

Permalink
Merge pull request appium#26 from sourishkrout/master
Browse files Browse the repository at this point in the history
Basis for improved error handling.
  • Loading branch information
admc committed Jan 21, 2013
2 parents 962253c + bc73d45 commit 826b736
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
48 changes: 24 additions & 24 deletions app/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ IOS.prototype.push = function(elem) {
me.instruments.sendCommand(target[0], function(result) {
if (typeof target[1] === 'function') {
if (typeof result === 'undefined') {
target[1]();
target[1](null, null);
} else {
try {
var jsonresult = JSON.parse(result);
target[1](jsonresult);
} catch (e) {
target[1](result);
target[1](null, jsonresult);
} catch (error) {
target[1](error, result);
}
}
}
Expand All @@ -126,7 +126,7 @@ IOS.prototype.findElementOrElements = function(selector, ctx, many, cb) {

var command = [ctx, ".findElement", ext, "AndSetKey", ext, "('", selector, "')"].join("");

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};
Expand All @@ -150,47 +150,47 @@ IOS.prototype.findElementsFromElement = function(element, strategy, selector, cb
IOS.prototype.setValue = function(elementId, value, cb) {
var command = ["elements['", elementId, "'].setValue('", value, "')"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.click = function(elementId, cb) {
var command = ["elements['", elementId, "'].tap()"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.getText = function(elementId, cb) {
var command = ["elements['", elementId, "'].getText()"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.getLocation = function(elementId, cb) {
var command = ["elements['", elementId, "'].getElementLocation()"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.getSize = function(elementId, cb) {
var command = ["elements['", elementId, "'].getElementSize()"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.keys = function(elementId, keys, cb) {
var command = ["sendKeysToActiveElement('", keys ,"')"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};
Expand All @@ -199,79 +199,79 @@ IOS.prototype.frame = function(frame, cb) {
frame = frame? frame : 'mainWindow';
var command = ["wd_frame = ", frame].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.implicitWait = function(seconds, cb) {
var command = ["setImplicitWait('", seconds, "')"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.elementDisplayed = function(elementId, cb) {
var command = ["elements['", elementId, "'].isDisplayed()"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.elementEnabled = function(elementId, cb) {
var command = ["elements['", elementId, "'].isEnabled()"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.getPageSource = function(cb) {
this.proxy("wd_frame.getPageSource()", function(json) {
this.proxy("wd_frame.getPageSource()", function(err, json) {
cb(null, json);
});
};

IOS.prototype.getAlertText = function(cb) {
this.proxy("target.frontMostApp().alert().name()", function(json) {
this.proxy("target.frontMostApp().alert().name()", function(err, json) {
cb(null, json);
});
};

IOS.prototype.postAcceptAlert = function(cb) {
this.proxy("target.frontMostApp().alert().defaultButton().tap()", function(json) {
this.proxy("target.frontMostApp().alert().defaultButton().tap()", function(err, json) {
cb(null, json);
});
};

IOS.prototype.postDismissAlert = function(cb) {
this.proxy("target.frontMostApp().alert().cancelButton().tap()", function(json) {
this.proxy("target.frontMostApp().alert().cancelButton().tap()", function(err, json) {
cb(null, json);
});
};

IOS.prototype.implicitWait = function(timeoutSeconds, cb) {
var command = ["setImplicitWait('", timeoutSeconds ,"')"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.getOrientation = function(cb) {
var command = "getScreenOrientation()";

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};

IOS.prototype.setOrientation = function(orientation, cb) {
var command = ["setScreenOrientation('", orientation ,"')"].join('');

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};
Expand All @@ -281,7 +281,7 @@ IOS.prototype.getScreenshot = function(cb) {
var command = ["takeScreenshot('screenshot", guid ,"')"].join('');

var shotPath = ["/tmp/", this.instruments.guid, "/Run 1/screenshot", guid, ".png"].join("");
this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
var delayTimes = 0;
var onErr = function() {
delayTimes++;
Expand Down Expand Up @@ -319,7 +319,7 @@ IOS.prototype.flick = function(xSpeed, ySpeed, swipe, cb) {
command = ["touchFlickFromSpeed(", xSpeed, ",", ySpeed,")"].join('');
}

this.proxy(command, function(json) {
this.proxy(command, function(err, json) {
cb(null, json);
});
};
Expand Down
2 changes: 1 addition & 1 deletion app/test/unit/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('IOS', function() {
return it('should execute one command at a time keeping the seq right', function(done) {
var intercept = []
, iterations = 100
, check = function(result) {
, check = function(err, result) {
intercept.push(result);
if (intercept.length >= iterations) {
for (var x=0; x < iterations; x++) {
Expand Down

0 comments on commit 826b736

Please sign in to comment.