Merge pull request #2184 from sebv/more-test-fixes

More test fixes
This commit is contained in:
seb vincent
2014-03-27 12:05:17 +08:00
10 changed files with 84 additions and 65 deletions
+1 -1
View File
@@ -210,7 +210,7 @@ exports.checkValidLocStrat = function (strat, includeWeb, cb) {
'class name'
];
var nativeStrats = [
'-ios-uiautomation'
'-ios_uiautomation'
];
var webStrats = [
'link text',
+1 -2
View File
@@ -28,7 +28,7 @@ var activateWebView = function (driver) {
return driver.contexts().then(function (ctxs) {
for (var idx in ctxs) {
var ctx = ctxs[idx];
if (ctx.indexOf('WEBVIEW') != -1) {
if (ctx.indexOf('WEBVIEW') !== -1) {
return ctx;
}
}
@@ -39,7 +39,6 @@ var activateWebView = function (driver) {
};
describe("gappium", function () {
describe('HelloGappium', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
+4 -11
View File
@@ -1,5 +1,6 @@
"use strict";
var env = require('../../helpers/env')
, iosReset = require('../../helpers/reset').iosReset
, path = require('path')
, iosApp = path.resolve(__dirname, "..", "..", "..", "sample-code", "apps",
"TestApp", "build", "Release-iphonesimulator", "TestApp.app")
@@ -47,21 +48,13 @@ var waitForLaunch = function (app, extraArgs, done) {
};
describe("appium - prelaunch -", function () {
this.timeout(env.MOCHA_TIMEOUT);
this.timeout(env.MOCHA_INIT_TIMEOUT);
describe('ios @skip-android-all', function () {
var proc;
beforeEach(function (done) {
exec('pkill -f iPhoneSimulator', function () {
done();
});
});
beforeEach(function (done) {
exec('pkill -f instruments', function () {
done();
});
if (env.IOS && env.RESET_IOS) { return iosReset().nodeify(done); }
else done();
});
afterEach(function (done) {
+1 -1
View File
@@ -11,7 +11,7 @@ chaiAsPromised.transferPromiseness = wd.transferPromiseness;
require("colors");
module.exports = function (context, desired, opts) {
context.timeout(env.MOCHA_TIMEOUT);
context.timeout(env.MOCHA_INIT_TIMEOUT);
var session = initSession(desired, opts);
@@ -7,6 +7,8 @@ var setup = require("../../common/setup-base")
, desired = require('./desired');
describe('testapp - location -', function () {
this.timeout(env.MOCHA_INIT_TIMEOUT);
var driver;
setup(this, desired).then(function (d) { driver = d; });
@@ -72,7 +74,6 @@ describe('testapp - location services -', function () {
_.extend(newDesired, {
locationServicesAuthorized: true
});
this.timeout(env.MOCHA_TIMEOUT);
it('should not work without bundleId', function (done) {
initSession(newDesired, {'no-retry': true}).setUp()
.then(function (err) {
@@ -207,80 +207,92 @@ describe('uicatalog - find element -', function () {
});
describe('FindElement(s)ByUIAutomation', function () {
var byUIA = '-ios_uiautomation';
// Running sequentially cause parallel runs crash appium
var filterDisplayed = function (els) {
var sequence = _.map(els, function (el) {
return function (displayedEls) {
return el.isDisplayed().then(function (isdisplayed) {
if (isdisplayed) displayedEls.push(el);
return displayedEls;
});
};
});
return sequence.reduce(Q.when, new Q([]));
};
before(function (done) {
driver.element('-ios_uiautomation', '.navigationBars()[0]')
.getAttribute('name').then(function (name) {
if (name !== 'UICatalog') {
driver.back().delay(2000).nodeify(done);
} else {
Q.delay(500).nodeify(done);
}
});
driver
.element(byUIA, '.navigationBars()[0]')
.getAttribute('name').then(function (name) {
if (name !== 'UICatalog') {
return driver.back().delay(2000);
} else {
return Q.delay(500);
}
}
).nodeify(done);
});
it('should process most basic UIAutomation query', function (done) {
driver.elements('-ios_uiautomation', '.elements()').then(function (els) {
els.length.should.equal(2);
_(els).each(function (el) {
el.should.exist;
});
}).nodeify(done);
driver
.elements(byUIA, '.elements()').then(filterDisplayed)
.should.eventually.have.length(2)
.nodeify(done);
});
it('should process UIAutomation queries if user leaves out the first period', function (done) {
driver.elements('-ios_uiautomation', 'elements()').then(function (els) {
els.length.should.equal(2);
_(els).each(function (el) {
el.should.exist;
});
}).nodeify(done);
driver
.elements(byUIA, 'elements()').then(filterDisplayed)
.should.eventually.have.length(2)
.nodeify(done);
});
it('should get a single element', function (done) {
driver.element('-ios_uiautomation', '.elements()[0]').getAttribute('name')
.should.become('UICatalog')
driver.element(byUIA, '.elements()[0]').getAttribute('name')
.should.become('UICatalog')
.nodeify(done);
});
it('should get a single element', function (done) {
driver.element('-ios_uiautomation', '.elements()[1]').getAttribute('name')
.should.become('Empty list')
driver.element(byUIA, '.elements()[1]').getAttribute('name')
.should.become('Empty list')
.nodeify(done);
});
it('should get single element as array', function (done) {
driver.elements('-ios_uiautomation', '.tableViews()[0]').then(function (els) {
els.length.should.equal(1);
}).nodeify(done);
driver
.elements(byUIA, '.tableViews()[0]')
.should.eventually.have.length(1)
.nodeify(done);
});
it('should find elements by index multiple times', function (done) {
driver.element('-ios_uiautomation', '.elements()[1].cells()[2]').getAttribute('name')
.should.become('TextFields, Uses of UITextField')
driver.element(byUIA, '.elements()[1].cells()[2]').getAttribute('name')
.should.become('TextFields, Uses of UITextField')
.nodeify(done);
});
it('should find elements by name', function (done) {
driver.element('-ios_uiautomation', '.elements()["UICatalog"]').getAttribute('name')
.should.become('UICatalog')
driver.element(byUIA, '.elements()["UICatalog"]').getAttribute('name')
.should.become('UICatalog')
.nodeify(done);
});
it('should find elements by name and index', function (done) {
driver.element('-ios_uiautomation', '.elements()["Empty list"].cells()[3]').getAttribute('name')
.should.become('SearchBar, Use of UISearchBar')
driver.element(byUIA, '.elements()["Empty list"].cells()[3]').getAttribute('name')
.should.become('SearchBar, Use of UISearchBar')
.nodeify(done);
});
describe('start from a given context instead of root target', function (done) {
describe('start from a given context instead of root target', function () {
it('should process a simple query', function (done) {
driver.element('-ios_uiautomation', '.elements()[1]').then(function (el) {
el.elements('-ios_uiautomation', '.elements()').then(function (els) {
els.length.should.equal(12);
_(els).each(function (el) {
el.should.exist;
});
}).nodeify(done);
driver.element(byUIA, '.elements()[1]').then(function (el) {
el
.elements(byUIA, '.elements()')
.should.eventually.have.length(12)
.nodeify(done);
});
});
it('should find elements by name', function (done) {
driver.element('-ios_uiautomation', '.elements()[1]').then(function (el) {
el.element('-ios_uiautomation', '.elements()["Buttons, Various uses of UIButton"]').then(function (el) {
el.should.exist;
}).nodeify(done);
driver.element(byUIA, '.elements()[1]').then(function (el) {
el
.element(byUIA, '.elements()["Buttons, Various uses of UIButton"]')
.should.eventually.exist
.nodeify(done);
});
});
});
+3 -3
View File
@@ -7,7 +7,6 @@ var env = {};
// local config
env.APPIUM_HOST = process.env.APPIUM_HOST || '127.0.0.1';
env.APPIUM_PORT = parseInt(process.env.APPIUM_PORT || 4723, 10);
env.MOCHA_TIMEOUT = parseInt(process.env.MOCHA_TIMEOUT || 180000, 10);
env.VERSION = process.env.VERSION;
// sauce
@@ -20,13 +19,14 @@ if (env.SAUCE) {
}
env.APPIUM_USERNAME = process.env.SAUCE_USERNAME;
env.APPIUM_PASSWORD = process.env.SAUCE_ACCESS_KEY;
env.MOCHA_TIMEOUT = parseInt(process.env.MOCHA_TIMEOUT || 500000, 10);
}
env.LAUNCH_TIMEOUT = JSON.parse(process.env.LAUNCH_TIMEOUT || 45000);
env.LAUNCH_TIMEOUT = JSON.parse(process.env.LAUNCH_TIMEOUT || 60000);
env.VERBOSE = process.env.VERBOSE;
env.ISOLATED_TESTS = process.env.ISOLATED_TESTS;
env.FAST_TESTS = !env.ISOLATED_TESTS;
env.RESET_IOS = process.env.RESET_IOS || true;
env.MOCHA_INIT_TIMEOUT = parseInt(process.env.MOCHA_INIT_TIMEOUT || 300000, 10);
// real device or emulator
env.REAL_DEVICE = process.env.REAL_DEVICE;
+10
View File
@@ -15,3 +15,13 @@ exports.androidUninstall = function (appPackage) {
.catch(function () {})
.then(function () { return Q.delay(500); });
};
exports.iosReset = function () {
if (env.VERBOSE) console.log('Resetting ios simulator.');
return exec('pkill -9 -f iPhoneSimulator')
.catch(function () {})
.then(function () { return exec('pkill -9 -f instruments'); })
.catch(function () {})
.then(function () { return exec('rm -rf $HOME/Library/Application\\ Support/iPhone\\ Simulator'); })
.catch(function () {});
};
+4
View File
@@ -3,6 +3,7 @@ var env = require('./env')
, wd = require("wd")
, Q = require("q")
, _ = require("underscore")
, iosReset = require('./reset').iosReset
, androidUninstall = require('./reset').androidUninstall;
require('colors');
@@ -62,6 +63,7 @@ module.exports.initSession = function (desired, opts) {
function init(remainingAttempts) {
if (env.VERBOSE) console.log("remainingAttempts -->", remainingAttempts);
return browser
.init(caps)
.catch(function (err) {
@@ -78,6 +80,8 @@ module.exports.initSession = function (desired, opts) {
var attempts = opts['no-retry'] ? 1 : 3;
return browser.chain()
.then(function () {
if (env.IOS && env.RESET_IOS) { return iosReset(); }
}).then(function () {
// if android uninstall package first
if (desired.device === 'Android' && desired['app-package']) {
return androidUninstall(desired['app-package']);
+1 -1
View File
@@ -1,3 +1,3 @@
-t 90000
-t 30000
-R spec
-r ./test/helpers/quit-gracefully