Merge pull request #204 from jlipps/master

mid-session app resetting refactoring, server flag
This commit is contained in:
Sebastian Tiedtke 2013-02-20 17:06:32 -08:00
Родитель c92b575e0d 77a3301ab9
Коммит 40cee44256
6 изменённых файлов: 105 добавлений и 43 удалений

Просмотреть файл

@ -11,7 +11,8 @@ var routing = require('./routing')
, copyLocalZip = helpers.copyLocalZip
, UUID = require('uuid-js')
, _ = require('underscore')
, ios = require('./ios');
, ios = require('./ios')
, status = require("./uiauto/lib/status");
var Appium = function(args) {
this.args = args;
@ -204,7 +205,7 @@ Appium.prototype.invoke = function() {
// in future all the blackberries go here.
this.active = 'iOS';
if (typeof this.devices[this.active] === 'undefined') {
this.devices[this.active] = ios(this.rest, this.args.app, this.args.udid, this.args.verbose, this.args.remove, this.args.warp);
this.devices[this.active] = ios(this.rest, this.args.app, this.args.udid, this.args.verbose, this.args.remove, this.args.warp, this.args.reset);
}
this.device = this.devices[this.active];
@ -223,20 +224,21 @@ Appium.prototype.onDeviceDie = function(code, cb) {
// reuse a bad app
this.args.app = this.origApp;
if (code !== null) {
logger.info('tossing device and devices');
logger.info('Clearing out appium devices');
this.devices = [];
this.device = null;
logger.info(this.progress + " sessions active =" + this.sessions.length);
//logger.info(this.progress + " sessions active =" + this.sessions.length);
this.sessions[this.progress] = {};
} else {
logger.info('not tossing device and devices because code=' + code);
logger.info('Not clearing out appium devices');
}
if (cb) {
if (this.active !== null) {
this.active = null;
this.invoke();
}
cb(null, {status: 0, value: null, sessionId: dyingSession});
cb(null, {status: status.codes.Success.code, value: null,
sessionId: dyingSession});
}
};
@ -254,6 +256,23 @@ Appium.prototype.stop = function(cb) {
});
};
Appium.prototype.reset = function(cb) {
logger.info("Resetting app mid-session");
var me = this
, oldId = this.sessionId;
this.stop(function() {
logger.info("Restarting app");
me.start(me.desiredCapabilities, function() {
me.sessionId = oldId;
cb(null, {status: status.codes.Success.code, value: null});
});
});
};
module.exports = function(args) {
return new Appium(args);
};

Просмотреть файл

@ -3,8 +3,6 @@
"use strict";
var status = require('./uiauto/lib/status')
, logger = require('../logger.js').get('appium')
, glob = require('glob')
, rimraf = require('rimraf')
, _s = require("underscore.string")
, _ = require('underscore');
@ -167,34 +165,7 @@ exports.getSessions = function(req, res) {
};
exports.reset = function(req, res) {
logger.info("Reset. Closing App.");
var oldId = req.appium.sessionId;
req.device.proxy('au.bundleId()', function(err, bId) {
var bundleId = bId.value;
var user = process.env.USER;
logger.info("Deleting plist for bundle: " + bundleId);
logger.info("User is: " + user);
req.appium.stop(function(){
glob("/Users/" + user + "/Library/Application Support/iPhone Simulator/**/" +
bundleId + ".plist", {}, function(err, files) {
if (err) {
logger.error("Could not remove plist: " + err.message);
} else {
_.each(files, function(file) {
rimraf(file, function() {
logger.info("Deleted " + file);
});
});
}
});
logger.info("Starting app.");
exports.createSession(req, res);
req.appium.sessionId = oldId;
});
});
req.appium.reset(getResponseHandler(req, res));
};
exports.deleteSession = function(req, res) {

Просмотреть файл

@ -30,13 +30,14 @@ var ProtocolError = function(message) {
this.name = "ProtocolError";
};
var IOS = function(rest, app, udid, verbose, removeTraceDir, warp) {
var IOS = function(rest, app, udid, verbose, removeTraceDir, warp, reset) {
this.rest = rest;
this.app = app;
this.udid = udid;
this.bundleId = null; // what we get from app on startup
this.verbose = verbose;
this.warp = warp;
this.reset = reset;
this.instruments = null;
this.queue = [];
this.progress = 0;
@ -113,15 +114,27 @@ IOS.prototype.start = function(cb, onDie) {
code = 1; // this counts as an error even if instruments doesn't think so
}
this.instruments = null;
var nexts = 0;
var next = function() {
nexts++;
if (nexts === 2) {
me.onStop(code);
me.onStop = null;
}
};
if (me.removeTraceDir && traceDir) {
rimraf(traceDir, function() {
logger.info("Deleted tracedir we heard about from instruments (" + traceDir + ")");
me.onStop(code);
me.onStop = null;
next();
});
} else {
me.onStop(code);
me.onStop = null;
next();
}
if (me.reset) {
me.cleanupAppState(next);
} else {
next();
}
};
@ -144,6 +157,38 @@ IOS.prototype.start = function(cb, onDie) {
};
IOS.prototype.cleanupAppState = function(cb) {
var user = process.env.USER
, me = this;
logger.info("Deleting plists for bundle: " + this.bundleId);
glob("/Users/" + user + "/Library/Application Support/iPhone Simulator/**/" +
me.bundleId + ".plist", {}, function(err, files) {
if (err) {
logger.error("Could not remove plist: " + err.message);
cb(err);
} else {
var filesExamined = 0;
var maybeNext = function() {
if (filesExamined === files.length) {
cb();
}
};
if (files.length) {
_.each(files, function(file) {
rimraf(file, function() {
logger.info("Deleted " + file);
filesExamined++;
maybeNext();
});
});
} else {
logger.info("No plist files found to remove");
cb();
}
}
});
};
IOS.prototype.listWebFrames = function(cb, exitCb) {
var me = this;
if (this.remote) {
@ -775,6 +820,6 @@ IOS.prototype.title = function(cb) {
}
};
module.exports = function(rest, app, udid, verbose, removeTraceDir, warp) {
return new IOS(rest, app, udid, verbose, removeTraceDir, warp);
module.exports = function(rest, app, udid, verbose, removeTraceDir, warp, reset) {
return new IOS(rest, app, udid, verbose, removeTraceDir, warp, reset);
};

Просмотреть файл

@ -34,6 +34,10 @@ module.exports = function() {
, { defaultValue: true, required: false, help: 'remove Instruments trace directories'
});
parser.addArgument([ '-s', '--reset' ]
, { defaultValue: true, required: false, help: 'reset app plist/state after each session'
});
parser.addArgument([ '-l', '--launch' ]
, { defaultValue: false, required: false, help: 'pre-launch the ios-sim'
});

Просмотреть файл

@ -27,6 +27,7 @@ module.exports.startAppium = function(appName, verbose, readyCb, doneCb) {
, verbose: verbose
, port: 4723
, warp: false
, reset: true
, launch: app ? true : false
, log: path.resolve(__dirname, "appium.log")
, address: '127.0.0.1'

Просмотреть файл

@ -0,0 +1,22 @@
/*global it:true */
"use strict";
var describeWd = require("../../helpers/driverblock.js").describeForApp('UICatalog')
, should = require('should');
describeWd('app reset', function(h) {
it("should be able to find elements after a soft reset", function(done) {
h.driver.elementsByTagName('tableView', function(err, els) {
should.not.exist(err);
els.length.should.equal(1);
h.driver.execute("mobile: reset", function(err) {
should.not.exist(err);
h.driver.elementsByTagName('tableView', function(err, els) {
should.not.exist(err);
els.length.should.equal(1);
done();
});
});
});
});
});