Merge pull request #3211 from imurchie/isaac-cert

Add tests for custom keystore, and fix Selendroid handling
This commit is contained in:
Jonathan Lipps
2014-07-24 12:03:16 -07:00
4 changed files with 75 additions and 3 deletions

View File

@@ -86,18 +86,35 @@ Selendroid.prototype.start = function (cb) {
this.adb = new ADB(this.args);
var modServerExists = false
, modAppPkg = null;
, modAppPkg = null
, modServerTimestamp = null;
var checkModServerExists = function (cb) {
this.selendroidServerPath = path.resolve(this.args.tmpDir,
'selendroid.' + this.args.appPackage + '.apk');
modAppPkg = this.args.appPackage + '.selendroid';
fs.stat(this.selendroidServerPath, function (err) {
fs.stat(this.selendroidServerPath, function (err, stat) {
modServerExists = !err;
if (stat) {
modServerTimestamp = stat.mtime.getTime();
}
cb();
});
}.bind(this);
var checkServerResigned = function (cb) {
if (modServerExists) {
fs.stat(this.selendroidServerPath, function (err, stat) {
if (stat && stat.mtime.getTime() > modServerTimestamp) {
modServerExists = false;
}
cb();
});
} else {
cb();
}
}.bind(this);
var conditionalUninstallSelendroid = function (cb) {
if (!modServerExists) {
logger.debug("Rebuilt selendroid apk does not exist, uninstalling " +
@@ -138,9 +155,10 @@ Selendroid.prototype.start = function (cb) {
this.prepareDevice.bind(this),
this.packageAndLaunchActivityFromManifest.bind(this),
checkModServerExists,
conditionalUninstallSelendroid,
conditionalInsertManifest,
this.checkSelendroidCerts.bind(this),
checkServerResigned,
conditionalUninstallSelendroid,
conditionalInstallSelendroid,
this.extractStringsSelendroid.bind(this),
this.uninstallApp.bind(this),

View File

@@ -0,0 +1,5 @@
"use strict";
var testBase = require('../common/keystore-base');
describe("android - keystore", testBase);

View File

@@ -0,0 +1,43 @@
"use strict";
var setup = require("./setup-base")
, env = require('../../helpers/env')
, exec = require('child_process').exec
, fs = require('fs')
, osType = require('os').type();
module.exports = function () {
var tmp = osType === 'Windows_NT' ? 'C:\\Windows\\Temp' : '/tmp';
var keystorePath = tmp + '/appiumtest.keystore';
var keyAlias = 'appiumtest';
var desired = {
app: "sample-code/apps/selendroid-test-app.apk",
appPackage: 'io.selendroid.testapp',
appActivity: '.HomeScreenActivity',
useKeystore: true,
keystorePath: keystorePath,
keyAlias: keyAlias
};
this.timeout(env.MOCHA_INIT_TIMEOUT);
var driver;
setup(this, desired).then(function (d) { driver = d; });
it('should be able to launch an app with custom keystore', function (done) {
fs.unlink(keystorePath, function (err) {
if (err) return done(err);
var cmd = 'keytool -genkey -v -keystore ' + keystorePath + ' -alias ' + keyAlias + ' -storepass android -keypass android -keyalg RSA -validity 14000';
var child = exec(cmd, function (err) {
if (err) return done(err);
driver
.getCurrentActivity()
.should.eventually.include(desired.appActivity)
.nodeify(done);
});
// answer the questions that `keytool` asks
child.stdin.write('Appium Testsuite\nAppium\nTest\nSan Francisco\nCalifornia\nUS\nyes\n');
});
});
};

View File

@@ -0,0 +1,6 @@
"use strict";
process.env.DEVICE = process.env.DEVICE || "selendroid";
var testBase = require('../common/keystore-base');
describe("selendroid - keystore", testBase);