mirror of
https://github.com/appium/appium.git
synced 2026-01-28 21:28:57 -06:00
add global error handling for appium controller methods
This commit is contained in:
@@ -138,6 +138,7 @@ exports.createSession = function(req, res) {
|
||||
} else {
|
||||
req.appium.start(req.body.desiredCapabilities, function(err, instance) {
|
||||
if (err) {
|
||||
logger.error("Failed to start an Appium session, err was: " + err);
|
||||
respondError(req, res, status.codes.NoSuchDriver);
|
||||
} else {
|
||||
next(req.appium.sessionId, instance);
|
||||
@@ -527,3 +528,7 @@ var mobileCmdMap = {
|
||||
exports.produceError = function(req, res) {
|
||||
req.device.proxy("thisisnotvalidjs", getResponseHandler(req, res));
|
||||
};
|
||||
|
||||
exports.crash = function() {
|
||||
throw new Error("We just tried to crash Appium!");
|
||||
};
|
||||
|
||||
@@ -57,8 +57,9 @@ module.exports = function(appium) {
|
||||
rest.post('/wd/hub/session/:sessionId?/execute', controller.execute);
|
||||
rest.get('/wd/hub/session/:sessionId?/title', controller.title);
|
||||
|
||||
// this is for testing purposes only
|
||||
// these are for testing purposes only
|
||||
rest.post('/wd/hub/produce_error', controller.produceError);
|
||||
rest.post('/wd/hub/crash', controller.crash);
|
||||
|
||||
// appium-specific extensions to JSONWP
|
||||
// these aren't part of JSONWP but we want them or something like them to be
|
||||
|
||||
@@ -6,6 +6,7 @@ var http = require('http')
|
||||
, appium = require('./app/appium')
|
||||
, bodyParser = require('./middleware').parserWrap
|
||||
, checkWarpDrive = require('./warp.js').checkWarpDrive
|
||||
, status = require('./app/uiauto/lib/status')
|
||||
, parser = require('./app/parser');
|
||||
|
||||
var doWarpCheck = function(wantWarp, cb) {
|
||||
@@ -51,6 +52,14 @@ var main = function(args, readyCb, doneCb) {
|
||||
rest.use(bodyParser);
|
||||
rest.use(express.methodOverride());
|
||||
rest.use(rest.router);
|
||||
// catch all error handler
|
||||
rest.use(function(e, req, res, next) {
|
||||
res.send(500, {
|
||||
status: status.codes.UnknownError.code
|
||||
, value: "ERROR running Appium command: " + e.message
|
||||
});
|
||||
next(e);
|
||||
});
|
||||
});
|
||||
|
||||
// Instantiate the appium instance
|
||||
|
||||
@@ -4,13 +4,17 @@
|
||||
var should = require("should")
|
||||
, serverUrl = 'http://localhost:4723'
|
||||
, serverHub = serverUrl + '/wd/hub/session'
|
||||
, path = require('path')
|
||||
, appPath = "../../../sample-code/apps/TestApp/build/Release-iphonesimulator/TestApp.app"
|
||||
, request = require('request');
|
||||
|
||||
var describeWithSession = function(desc, tests) {
|
||||
describe(desc, function() {
|
||||
var sessObj = {sessionId: null};
|
||||
beforeEach(function(done) {
|
||||
var caps = {desiredCapabilities: {}};
|
||||
var caps = {desiredCapabilities: {
|
||||
app: path.resolve(__dirname, appPath)
|
||||
}};
|
||||
request.post({url: serverHub, json: caps}, function(err, res) {
|
||||
should.not.exist(err);
|
||||
res.statusCode.should.equal(303);
|
||||
@@ -56,7 +60,7 @@ describe('JSONWP request', function() {
|
||||
request.post(url, function(err, res, body) {
|
||||
should.not.exist(err);
|
||||
res.statusCode.should.equal(501);
|
||||
body.should.equal("Not Implemented");
|
||||
JSON.parse(body).status.should.equal(13);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -79,7 +83,20 @@ describe('JSONWP request', function() {
|
||||
res.statusCode.should.equal(500);
|
||||
should.ok(body);
|
||||
body = JSON.parse(body);
|
||||
should.ok(body.value.message);
|
||||
should.ok(body.value);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
describeWithSession('that generates a server crash', function() {
|
||||
it('should respond with a 500', function(done) {
|
||||
var url = serverUrl + '/wd/hub/crash';
|
||||
request.post(url, function(err, res, body) {
|
||||
should.not.exist(err);
|
||||
res.statusCode.should.equal(500);
|
||||
should.ok(body);
|
||||
body = JSON.parse(body);
|
||||
should.ok(body.value);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user