ported over the java contact app test to node since the test is outdated

This commit is contained in:
Wa Wang
2014-05-15 13:38:04 -07:00
parent 0ef5014c4f
commit f9464a9fd9

View File

@@ -8,6 +8,11 @@ run:
var wd = require("wd"),
path = require('path');
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
var Q = require('q');
var desired = {
'appium-version': '1.0',
@@ -33,65 +38,27 @@ browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
var bc = function (t) { return "//button[contains(@text, '" + t + "')]"; };
var ec = function (t) { return "//editText[contains(@text, '" + t + "')]"; };
var tc = function (t) { return "//text[contains(@text, '" + t + "')]"; };
function deleteUser(name, timeout) {
return browser
.waitForElementByXPath(tc(name), timeout).click()
.elementByName('More options')
.click()
.elementByXPath(tc('Delete')).click()
.waitForElementByXPath(bc('OK'), TIME_BASE_UNIT).click();
}
// Run the test
browser
.init(desired).then(function () {
return browser
// waiting for app initialization
.waitForElementByXPath(tc('contacts'), 10 * TIME_BASE_UNIT)
//try to delete contact if it is there
.then(function () {
return deleteUser('John Smith', TIME_BASE_UNIT / 10)
.catch(function () {/* ignore */});
})
.waitForElementByXPath(bc('Create'), 2 * TIME_BASE_UNIT).click()
// There may be a confirmation stage
.then(function () {
return browser
.waitForElementByXPath(bc('Keep'), TIME_BASE_UNIT)
.click()
.catch(function () {/* ignore */});
})
// Adding user
.waitForElementByXPath(ec('Name'), 2 * TIME_BASE_UNIT)
.sendKeys("John Smith")
.elementByXPath(ec('Phone'))
.sendKeys("(555) 555-5555")
.elementByXPath(ec('Email'))
.sendKeys("john.smith@google.io")
.elementByXPath(tc('Done')).click()
// Editing user
.waitForElementByName("Edit", TIME_BASE_UNIT * 10) // superslow
.click()
.waitForElementByXPath(bc('Add another field'), 2 * TIME_BASE_UNIT)
// add new contact
.elementByName("Add Contact")
.click()
.waitForElementByXPath(tc('Address'), 2 * TIME_BASE_UNIT)
.elementsByClassName("android.widget.EditText")
.then(function(elements){
return Q.all([
elements[0].type("some name")
.text()
.should.eventually.include('some'),
elements[2].type("Some@example.com")
.text()
.should.eventually.include('Some@example.com')
]);
//console.log(elements.length);
})
.elementByName("Save")
.click()
.waitForElementByXPath(ec('Address'), 2 * TIME_BASE_UNIT)
.sendKeys("123 Appium Street")
.elementByXPath(tc('Done')).click()
// Deleting user
.then(deleteUser.bind(null, 'John Smith', 2 * TIME_BASE_UNIT))
.fin(function () {
return browser
.sleep(TIME_BASE_UNIT) // waiting a bit before quitting