node.js sample rewrite

This commit is contained in:
sebv
2014-06-08 15:28:27 +08:00
parent 0dff3896ff
commit 5c528e0565
36 changed files with 1287 additions and 856 deletions
+21
View File
@@ -0,0 +1,21 @@
{
"laxcomma": true,
"strict": true,
"undef": true,
"unused": true,
"trailing": true,
"node": true,
"eqeqeq": true,
"trailing": true,
"expr": true,
"white": true,
"indent": 2,
"globals": {
"describe": true,
"it": true,
"before": true,
"after": true,
"beforeEach": true,
"afterEach": true
}
}
+112
View File
@@ -0,0 +1,112 @@
#Node.js samples
##iOS
### local
- `./reset.sh --hardcore --ios`
- `mocha sample-code/examples/node/ios-simple.js`
- `mocha sample-code/examples/node/ios-complex.js`
- `mocha sample-code/examples/node/ios-webview.js`
- `mocha sample-code/examples/node/ios-local-server.js`
### dev (run against locally built app)
- `./reset.sh --hardcore --ios --dev`
- `DEV=1 mocha sample-code/examples/node/ios-simple.js`
- `DEV=1 mocha sample-code/examples/node/ios-complex.js`
- `DEV=1 mocha sample-code/examples/node/ios-webview.js`
- `DEV=1 mocha sample-code/examples/node/ios-local-server.js`
### Sauce Labs
- `./reset.sh --hardcore --ios`
- `export SAUCE_USERNAME=<SAUCE_USERNAME>`
- `export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>`
- `SAUCE=1 mocha sample-code/examples/node/ios-simple.js`
- `SAUCE=1 mocha sample-code/examples/node/ios-complex.js`
- `SAUCE=1 mocha sample-code/examples/node/ios-webview.js`
### Sauce Labs + Sauce Connect
- `./reset.sh --hardcore --ios`
- `export SAUCE_USERNAME=<SAUCE_USERNAME>`
- `export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>`
- Install and start Sauce Connect (see [doc here](https://saucelabs.com/docs/connect))
- `SAUCE=1 mocha sample-code/examples/node/ios-local-server.js`
##Android
### local
- `./reset.sh --hardcore --android`
- `mocha sample-code/examples/node/android-simple.js`
- `mocha sample-code/examples/node/android-complex.js`
- `mocha sample-code/examples/node/android-webview.js`
- `mocha sample-code/examples/node/android-local-server.js`
### dev (run against locally built app)
- `./reset.sh --hardcore --android --dev`
- `DEV=1 mocha sample-code/examples/node/android-simple.js`
- `DEV=1 mocha sample-code/examples/node/android-complex.js`
- `DEV=1 mocha sample-code/examples/node/android-webview.js`
- `DEV=1 mocha sample-code/examples/node/android-local-server.js`
### Sauce Labs
- `./reset.sh --hardcore --android`
- `export SAUCE_USERNAME=<SAUCE_USERNAME>`
- `export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>`
- `SAUCE=1 mocha sample-code/examples/node/android-simple.js`
- `SAUCE=1 mocha sample-code/examples/node/android-complex.js`
- `SAUCE=1 mocha sample-code/examples/node/android-webview.js`
### Sauce Labs + Sauce Connect
- `./reset.sh --hardcore --android`
- `export SAUCE_USERNAME=<SAUCE_USERNAME>`
- `export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>`
- Install and start Sauce Connect (see [doc here](https://saucelabs.com/docs/connect))
- `SAUCE=1 mocha sample-code/examples/node/android-local-server.js`
##Selendroid
### local
- `./reset.sh --hardcore --android --selendroid`
- `mocha sample-code/examples/node/selendroid-simple.js`
### Sauce Labs
- `./reset.sh --hardcore --android --selendroid`
- `SAUCE=1 mocha sample-code/examples/node/selendroid-simple.js`
##Node.js 0.11 + Generator with Yiewd
### local
- `./reset.sh --hardcore --ios`
- switch to node > 0.11
- `mocha --harmony sample-code/examples/node/ios-yiewd.js`
### Sauce Labs
- `./reset.sh --hardcore --ios`
- switch to node > 0.11
- `export SAUCE_USERNAME=<SAUCE_USERNAME>`
- `export SAUCE_ACCESS_KEY=<SAUCE_ACCESS_KEY>`
- `SAUCE=1 mocha --harmony sample-code/examples/node/ios-yiewd.js`
@@ -0,0 +1,197 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
actions = require("./helpers/actions"),
serverConfigs = require('./helpers/appium-servers'),
_p = require('./helpers/promise-utils'),
Q = require('q');
wd.addPromiseChainMethod('swipe', actions.swipe);
describe("android complex", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = process.env.SAUCE ?
_.clone(require("./helpers/caps").android18) :
_.clone(require("./helpers/caps").android19);
desired.app = require("./helpers/apps").androidApiDemos;
if (process.env.SAUCE) {
desired.name = 'android - complex';
desired.tags = ['sample'];
}
return driver
.init(desired)
.setImplicitWaitTimeout(5000);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should find an element", function () {
return driver
.elementByXPath('//android.widget.TextView[@text=\'Animation\']')
.elementByXPath('//android.widget.TextView')
.text().should.become('API Demos')
.elementsByXPath('//android.widget.TextView[contains(@text, "Animat")]')
.then(_p.filterDisplayed).first()
.then(function (el) {
if (!process.env.SAUCE) {
return el.text().should.become('Animation');
}
}).elementByName('App').click()
.sleep(3000)
.elementsByAndroidUIAutomator('new UiSelector().clickable(true)')
.should.eventually.have.length.above(10)
.elementByXPath('//android.widget.TextView[@text=\'Action Bar\']')
.should.eventually.exist
.elementsByXPath('//android.widget.TextView')
.then(_p.filterDisplayed).first()
.text().should.become('API Demos')
.back().sleep(1000);
});
it("should scroll", function () {
return driver
.elementByXPath('//android.widget.TextView[@text=\'Animation\']')
.elementsByXPath('//android.widget.TextView')
.then(function (els) {
return Q.all([
els[7].getLocation(),
els[3].getLocation()
]).then(function (locs) {
console.log('locs -->', locs);
return driver.swipe({
startX: locs[0].x, startY: locs[0].y,
endX: locs[1].x, endY: locs[1].y,
duration: 800
});
});
});
});
it("should draw a smiley", function () {
function findTouchPaint() {
return driver
.elementsByClassName('android.widget.TextView')
.then(function (els) {
return Q.all([
els[els.length - 1].getLocation(),
els[0].getLocation()
]).then(function (locs) {
return driver.swipe({
startX: locs[0].x, startY: locs[0].y,
endX: locs[1].x, endY: locs[1].y,
duration: 800
});
});
}).elementByName('Touch Paint')
.catch(function () {
return findTouchPaint();
});
}
return driver
.elementByName('Graphics').click()
.then(findTouchPaint)
.click()
.sleep(5000)
.then(function () {
var a1 = new wd.TouchAction();
a1.press({x: 150, y: 100}).release();
var a2 = new wd.TouchAction();
a2.press({x: 250, y: 100}).release();
var smile = new wd.TouchAction();
smile
.press({x:110, y:200})
.moveTo({x:1, y:1})
.moveTo({x:1, y:1})
.moveTo({x:1, y:1})
.moveTo({x:1, y:1})
.moveTo({x:1, y:1})
.moveTo({x:2, y:1})
.moveTo({x:2, y:1})
.moveTo({x:2, y:1})
.moveTo({x:2, y:1})
.moveTo({x:2, y:1})
.moveTo({x:3, y:1})
.moveTo({x:3, y:1})
.moveTo({x:3, y:1})
.moveTo({x:3, y:1})
.moveTo({x:3, y:1})
.moveTo({x:4, y:1})
.moveTo({x:4, y:1})
.moveTo({x:4, y:1})
.moveTo({x:4, y:1})
.moveTo({x:4, y:1})
.moveTo({x:5, y:1})
.moveTo({x:5, y:1})
.moveTo({x:5, y:1})
.moveTo({x:5, y:1})
.moveTo({x:5, y:1})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:0})
.moveTo({x:5, y:-1})
.moveTo({x:5, y:-1})
.moveTo({x:5, y:-1})
.moveTo({x:5, y:-1})
.moveTo({x:5, y:-1})
.moveTo({x:4, y:-1})
.moveTo({x:4, y:-1})
.moveTo({x:4, y:-1})
.moveTo({x:4, y:-1})
.moveTo({x:4, y:-1})
.moveTo({x:3, y:-1})
.moveTo({x:3, y:-1})
.moveTo({x:3, y:-1})
.moveTo({x:3, y:-1})
.moveTo({x:3, y:-1})
.moveTo({x:2, y:-1})
.moveTo({x:2, y:-1})
.moveTo({x:2, y:-1})
.moveTo({x:2, y:-1})
.moveTo({x:2, y:-1})
.moveTo({x:1, y:-1})
.moveTo({x:1, y:-1})
.moveTo({x:1, y:-1})
.moveTo({x:1, y:-1})
.moveTo({x:1, y:-1})
.release();
var ma = new wd.MultiAction().add(a1, a2, smile);
return driver.performMultiTouch(ma)
// so you can see it
.sleep(10000)
.back().sleep(1000)
.back().sleep(1000);
});
});
});
@@ -0,0 +1,55 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers'),
localServer = require('./helpers/local-server');
describe("android local server", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
localServer.start();
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = process.env.SAUCE ?
_.clone(require("./helpers/caps").android18) :
_.clone(require("./helpers/caps").android19);
desired.app = require("./helpers/apps").androidApiDemosLocal;
if (process.env.SAUCE) {
desired.name = 'android - local server';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function () {
localServer.stop();
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should open the app", function () {
return driver
.elementByAccessibilityId('Graphics')
.should.eventually.exist;
});
});
@@ -0,0 +1,63 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("android simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = process.env.SAUCE ?
_.clone(require("./helpers/caps").android18) :
_.clone(require("./helpers/caps").android19);
desired.app = require("./helpers/apps").androidApiDemos;
if (process.env.SAUCE) {
desired.name = 'android - simple';
desired.tags = ['sample'];
}
return driver
.init(desired)
.setImplicitWaitTimeout(3000);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should find an element", function () {
return driver
.elementByAccessibilityId('Graphics')
.click()
.elementByAccessibilityId('Arcs')
.should.eventually.exist
.back()
.elementByName('App')
.should.eventually.exist
.elementsByAndroidUIAutomator('new UiSelector().clickable(true)')
.should.eventually.have.length(12)
.elementsByAndroidUIAutomator('new UiSelector().enabled(true)')
.should.eventually.have.length.above(20)
.elementByXPath('//android.widget.TextView[@text=\'API Demos\']')
.should.exists;
});
});
@@ -0,0 +1,63 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("android webview", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = process.env.SAUCE ?
_.clone(require("./helpers/caps").android18) :
_.clone(require("./helpers/caps").android19);
desired.app = require("./helpers/apps").selendroidTestApp;
if (process.env.SAUCE) {
desired.name = 'android - webview';
desired.tags = ['sample'];
}
return driver
.init(desired)
.setImplicitWaitTimeout(3000);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should switch to webview", function () {
return driver
.elementByName('buttonStartWebviewCD')
.click()
.sleep(5000)
.contexts()
.context('WEBVIEW_0')
.elementById('name_input')
.clear()
.sendKeys('Appium User')
.sendKeys(wd.SPECIAL_KEYS.Return)
.source().then(function (source) {
source.should.include('This is my way of saying hello');
source.should.include('Appium User');
});
});
});
@@ -0,0 +1,16 @@
<html>
<head>
<title>Appium Rocks</title>
</head>
<body>
<h1>Appium Rocks</h1>
<footer>
<p id='wow'>
Wow this is so cool!
</p>
</footer>
</body>
</html>
@@ -0,0 +1,13 @@
"use strict";
var wd = require('wd');
exports.swipe = function (opts) {
var action = new wd.TouchAction();
action
.press({x: opts.startX, y: opts.startY})
.wait(opts.duration)
.moveTo({x: opts.endX, y: opts.endY})
.release();
return this.performTouch(action);
};
@@ -0,0 +1,12 @@
exports.local = {
host: 'localhost',
port: 4723
};
exports.sauce = {
host: 'ondemand.saucelabs.com',
port: 80,
username: process.env.SAUCE_USERNAME,
password: process.env.SAUCE_ACCESS_KEY
};
+16
View File
@@ -0,0 +1,16 @@
if (process.env.DEV) {
exports.iosTestApp = "sample-code/apps/TestApp/build/Release-iphonesimulator/TestApp.app";
exports.iosWebviewApp = "sample-code/apps/WebViewApp/build/Release-iphonesimulator/WebViewApp.app";
exports.iosUICatalogApp = "sample-code/apps/UICatalog/build/Release-iphonesimulator/UICatalog.app";
exports.androidApiDemos = "sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk";
exports.selendroidTestApp = "sample-code/apps/selendroid-test-app.apk";
} else {
exports.iosTestApp = "http://appium.github.io/appium/assets/TestApp7.1.app.zip";
exports.iosWebviewApp = "http://appium.github.io/appium/assets/WebViewApp7.1.app.zip";
exports.iosUICatalogApp = "http://appium.github.io/appium/assets/UICatalog7.1.app.zip";
exports.androidApiDemos = "http://appium.github.io/appium/assets/ApiDemos-debug.apk";
exports.selendroidTestApp = "http://appium.github.io/appium/assets/selendroid-test-app-0.10.0.apk";
exports.iosWebviewAppLocal = "http://localhost:3000/WebViewApp7.1.app.zip";
exports.androidApiDemosLocal = "http://localhost:3000/ApiDemos-debug.apk";
}
+37
View File
@@ -0,0 +1,37 @@
exports.ios71 = {
browserName: '',
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
app: undefined // will be set later
};
exports.android18 = {
browserName: '',
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.3',
deviceName: 'Android Emulator',
app: undefined // will be set later
};
exports.android19 = {
browserName: '',
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.4.2',
deviceName: 'Android Emulator',
app: undefined // will be set later
};
exports.selendroid16 = {
browserName: '',
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.1',
automationName: 'selendroid',
deviceName: 'Android Emulator',
app: undefined // will be set later
};
@@ -0,0 +1,29 @@
"use strict";
var express = require('express'),
app = express(),
path = require('path');
app.use(express.static(__dirname + '/static'));
app.get('/index.html', function (req, res) {
res.sendfile(path.resolve(__dirname, '../assets/index.html'));
});
app.get('/WebViewApp7.1.app.zip', function (req, res) {
res.sendfile(path.resolve(__dirname, '../../../../assets/WebViewApp7.1.app.zip'));
});
app.get('/ApiDemos-debug.apk', function (req, res) {
res.sendfile(path.resolve(__dirname, '../../../../assets/ApiDemos-debug.apk'));
});
var server;
exports.start = function () {
server = app.listen(3000);
};
exports.stop = function () {
server.close();
};
@@ -0,0 +1,14 @@
"use strict";
exports.configure = function (driver) {
// See whats going on
driver.on('status', function (info) {
console.log(info.cyan);
});
driver.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
driver.on('http', function (meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});
};
@@ -0,0 +1,50 @@
"use strict";
var Q = require('q'),
_ = require('underscore');
exports.each = function (fn) {
return function (els) {
var seq = _(els).map(function (el, i) {
return function () {
return fn(el, i);
};
});
// iterating
return seq.reduce(Q.when, new Q()).then(function () {
return els;
});
};
};
exports.filter = function (fn) {
return function (els) {
var seq = _(els).map(function (el, i) {
return function (filteredEls) {
return fn(el, i).then(function (isOk) {
if (isOk) filteredEls.push(el);
return filteredEls;
});
};
});
// iterating
return seq.reduce(Q.when, new Q([]));
};
};
exports.printNames = exports.each(function (el, i) {
return el.getAttribute('name').print(i + "--> ");
});
exports.filterDisplayed = exports.filter(function (el) {
return el.isDisplayed();
});
exports.filterWithName = function (name) {
return exports.filter(function (el) {
return el.getAttribute('name').then(function (_name) {
return _name === name;
});
});
};
@@ -0,0 +1,10 @@
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
var should = chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
exports.should = should;
+226
View File
@@ -0,0 +1,226 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
Q = require('q'),
serverConfigs = require('./helpers/appium-servers'),
_p = require('./helpers/promise-utils'),
fs = require('fs');
describe("ios simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").ios71);
desired.app = require("./helpers/apps").iosUICatalogApp;
if (process.env.SAUCE) {
desired.name = 'ios - complex';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
function clickMenuItem(name) {
return driver
.elementByName(name)
.catch(function () {
return driver
.elementByClassName('UIATableView')
.elementsByClassName('>','UIATableCell')
.then(_p.filterWithName(name)).first();
}).click();
}
it("should print every menu item", function () {
return driver
.elementByClassName('UIATableView')
.elementsByClassName('>','UIATableCell')
.then(_p.printNames);
});
it("should find an element", function () {
return driver
// first view in UICatalog is a table
.elementByClassName('UIATableView')
.should.eventually.exist
// check the number of cells/rows inside the table
.elementsByClassName('UIATableCell')
.then(_p.filterDisplayed)
.then(function (els) {
els.should.have.length.above(6);
return els;
})
// various checks
.first().getAttribute('name')
.should.become('Action Sheets, AAPLActionSheetViewController')
.waitForElementByClassName('UIANavigationBar')
.should.eventually.exist;
});
it("should switch context", function () {
return clickMenuItem('Web View, AAPLWebViewController')
// get the contexts and switch to webview
.contexts().should.eventually.deep.equal(
['NATIVE_APP','WEBVIEW_1']
).context('WEBVIEW_1')
// find the store link
.sleep(1000)
.waitForElementById('gn-apple')
.should.eventually.exist
// leave the webview
.context('NATIVE_APP').sleep(1000)
//Verify we are out of the webview
.waitForElementByClassName('UIAScrollView')
.should.eventually.exist
// back to main menu
.back();
});
it("should get an element location", function () {
return driver.elementsByClassName("UIATableCell")
.then(_p.filterDisplayed)
.at(2)
.getLocation()
.then(function (loc) {
loc.x.should.equal(0);
loc.y.should.be.above(100);
});
});
it("should take screenshots", function () {
return driver
// base64 screeshot
.takeScreenshot()
.should.eventually.exist
// save screenshot to local file
.then(function () {
try {
fs.unlinkSync('/tmp/foo.png');
} catch (ign) {}
fs.existsSync('/tmp/foo.png').should.not.be.ok;
})
.saveScreenshot('/tmp/foo.png')
.then(function () {
fs.existsSync('/tmp/foo.png').should.be.ok;
});
});
it("should edit a text field", function () {
var el, defaultValue;
return clickMenuItem('Text Fields, AAPLTextFieldViewController')
// get the field and the default/empty text
.elementByClassName('UIATextField')
.then(function (_el) {
el = _el;
return el.getValue(); })
.then(function (val) { defaultValue = val; })
// type something
.then(function () {
return el
.sendKeys('1234 appium')
.getValue().should.become('1234 appium')
.elementByName('Done').click().sleep(1000); // dismissing keyboard
})
// clear the field
.then(function () { return el.clear(); })
.then(function () { el.getValue().should.become(defaultValue); })
// back to main menu
.back();
});
it("should trigger/accept/dismiss an alert", function () {
return clickMenuItem('Alert Views, AAPLAlertViewController')
// trigger simple alert
.elementByName('Simple').click()
.alertText().should.eventually.include('A Short Title Is Best')
.dismissAlert()
// trigger modal alert with cancel & ok buttons
.elementByName('Okay / Cancel').click()
.alertText().should.eventually.include('A Short Title Is Best')
.acceptAlert()
// back to main menu
.back();
});
it("should set a slider value", function () {
var slider;
return clickMenuItem('Sliders, AAPLSliderViewController')
// retrieve slider, check initial value
.elementByClassName("UIASlider")
.then(function (_slider) { slider = _slider; })
.then(function () {
return slider.getValue().should.become('42%');
})
// change value
.then(function () { return slider.setImmediateValue("0%"); })
.then(function () {
return slider.getValue().should.become('0%');
})
// back to main menu
.back();
});
if (!process.env.SAUCE) {
it("should retrieve the session list", function () {
driver.sessions()
.then(function (sessions) {
JSON.stringify(sessions).should.include(driver.getSessionId());
});
});
}
it("should retrieve an element size", function () {
return Q.all([
driver.elementByClassName('UIATableView').getSize(),
driver.elementByClassName('UIATableCell').getSize(),
]).then(function (sizes) {
sizes[0].width.should.equal(sizes[1].width);
sizes[0].height.should.not.equal(sizes[1].height);
});
});
it("should retrieve an element size", function () {
var mainMenuSource;
// main menu source
return driver
.source().then(function (source) {
mainMenuSource = source;
mainMenuSource.should.include('UIAStaticText');
mainMenuSource.should.include('Text Fields');
})
// text fields section source
.then(function () {
return clickMenuItem("Text Fields, AAPLTextFieldViewController");
}).source(function (textFieldSectionSource) {
textFieldSectionSource.should.include('UIAStaticText');
textFieldSectionSource.should.include('Text Fields');
textFieldSectionSource.should.not.equal(textFieldSectionSource);
})
// back to main menu
.back();
});
});
@@ -0,0 +1,59 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers'),
localServer = require('./helpers/local-server');
describe("ios local server", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
localServer.start();
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").ios71);
desired.app = require("./helpers/apps").iosWebviewAppLocal;
if (process.env.SAUCE) {
desired.name = 'ios - local server';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function () {
localServer.stop();
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should get the url", function () {
return driver
.elementByXPath('//UIATextField[@value=\'Enter URL\']')
.sendKeys('http://localhost:3000/index.html')
.elementByName('Go').click()
.elementByClassName('UIAWebView').click() // dismissing keyboard
.context('WEBVIEW')
.sleep(3000)
.waitForElementById('wow')
.text().should.eventually.include('so cool');
});
});
+84
View File
@@ -0,0 +1,84 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
Q = require('q'),
actions = require("./helpers/actions"),
serverConfigs = require('./helpers/appium-servers');
wd.addPromiseChainMethod('swipe', actions.swipe);
describe("ios simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").ios71);
desired.app = require("./helpers/apps").iosTestApp;
if (process.env.SAUCE) {
desired.name = 'ios - simple';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
function populate() {
var seq = _(['IntegerA', 'IntegerB']).map(function (name) {
return function (sum) {
return driver.waitForElementByName(name, 3000).then(function (el) {
var x = _.random(0,10);
sum += x;
return el.type('' + x).then(function () { return sum; })
.elementByName('Done').click().sleep(1000); // dismissing keyboard
}).then(function () { return sum; });
};
});
return seq.reduce(Q.when, new Q(0));
}
it("should compute the sum", function () {
return driver
.resolve(populate()).then(function (sum) {
return driver.
elementByAccessibilityId('ComputeSumButton')
.click().sleep(1000)
.elementByIosUIAutomation('elements().withName("Answer");')
.text().should.become("" + sum);
});
});
it("should swipe", function () {
return driver
.waitForElementByName('Test Gesture', 5000).click()
.sleep(1000)
.elementByName('OK').click()
.sleep(1000)
.elementByXPath('//UIAMapView').getLocation()
.then(function (loc) {
return driver.swipe({ startX: loc.x, startY: loc.y,
endX: 0.5, endY: loc.y, duration: 800 });
});
});
});
-82
View File
@@ -1,82 +0,0 @@
"use strict";
/*
LOCAL APPIUM:
node ios-wd-raw.js
APPIUM ON SAUCE LABS:
1/ Set your sauce credentials (SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables)
2/ SAUCE=1 node ios-wd-raw.js
*/
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var host, port, username, accessKey, desired;
var desired = {
browserName: '',
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
app: "http://appium.s3.amazonaws.com/TestApp6.0.app.zip",
'deviceOrientation': 'portrait',
};
if (process.env.SAUCE) {
// Sauce Labs config
host = "ondemand.saucelabs.com";
port = 80;
username = process.env.SAUCE_USERNAME;
accessKey = process.env.SAUCE_ACCESS_KEY;
desired.name = "Appium: with WD Mocha";
} else {
// local config
host = "localhost";
port = 4723;
}
// Instantiate a new browser session
var browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser
.init(desired)
.then(function () {
browser
.elementsByIosUIAutomation('.textFields();').then(function (els) {
return els[0].type('2').then(function () {
return els[1].type('3');
});
})
.elementByIosUIAutomation('.buttons()')
.click()
.elementByClassName('UIAStaticText')
.text().should.become("5")
.catch(function(err) { console.log(err); })
.fin(function () {
return browser
.sleep(3000)
.quit();
});
})
.catch(function (err) {
console.log(err);
throw err;
})
.done();
+59
View File
@@ -0,0 +1,59 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("ios simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").ios71);
desired.app = require("./helpers/apps").iosWebviewApp;
if (process.env.SAUCE) {
desired.name = 'ios - webview';
desired.tags = ['sample'];
}
return driver.init(desired);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should get the url", function () {
return driver
.elementByXPath('//UIATextField[@value=\'Enter URL\']')
.sendKeys('https://www.google.com')
.elementByName('Go').click()
.elementByClassName('UIAWebView').click() // dismissing keyboard
.context('WEBVIEW')
.sleep(1000)
.waitForElementByName('q', 5000)
.sendKeys('sauce labs')
.sendKeys(wd.SPECIAL_KEYS.Return)
.sleep(1000)
.title().should.eventually.include('sauce labs');
});
});
@@ -1,131 +0,0 @@
/* jshint esnext: true */
"use strict";
/*
First you need to install node > 0.11 to run this.
(You may use this https://github.com/visionmedia/n for easy install/switch
between node versions)
LOCAL APPIUM (not working with ios 7, try on Sauce Labs instead):
node --harmony ios-yiewd-catalog.js
APPIUM ON SAUCE LABS USING SAUCE CONNECT:
1/ Set your sauce credentials (SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables)
2/ Start Sauce Conect
3/ SAUCE_CONNECT=1 node --harmony ios-yiewd-catalog.js
*/
var wd = require("yiewd")
, path = require("path");
require("colors");
var staticServer = require('node-static'),
path = require("path"),
http = require('http'),
assetDir = path.resolve(__dirname, "../../../assets"),
fileServer = new staticServer.Server(assetDir);
var host, port, username, accessKey, desired, server;
var desired = {
browserName: '',
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
'deviceOrientation': 'portrait'
};
if (process.env.SAUCE_CONNECT) {
// Sauce Labs + Sauce Connect config
// create a local server to host our app
server = http.createServer(function (req, res) {
req.addListener('end', function () {
fileServer.serve(req, res);
}).resume();
}).listen(8080);
host = "localhost";
port = 4445;
username = process.env.SAUCE_USERNAME;
accessKey = process.env.SAUCE_ACCESS_KEY;
desired.name = "Appium: with WD";
desired.app = 'http://localhost:8080/UICatalog6.1.app.zip';
} else {
host = "localhost";
port = 4723;
desired.app = 'assets/UICatalog6.1.app.zip';
}
var browser = wd.remote(host, port, username, accessKey);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
browser.run(function* () {
try {
yield this.init(desired);
yield this.elementByName("Buttons, Various uses of UIButton").click();
var btns = yield this
.elementsByClassName('UIAButton');
for (var i = 1; i < 4; i++) {
yield btns[i].click();
}
yield btns[0].click();
yield this.elementByName("Controls, Various uses of UIControl").click();
var stdSwitch = yield this.elementByXPath("//UIASwitch[@name='Standard']");
yield stdSwitch.sendKeys(true);
yield stdSwitch.sendKeys(false);
var stdSlider = yield this.elementByXPath("//UIASlider[@name='Standard']");
yield stdSlider.sendKeys("0.25");
yield stdSlider.sendKeys("0.8");
var cstSlider = yield this.elementByXPath("//UIASlider[@name='Custom']");
yield cstSlider.sendKeys("1.0");
// TODO: not visible, cannot scroll to it in ios71
// var pages = yield this.elementByClassName("UIAPageIndicator");
// yield pages.moveTo();
// for (var i = 0; i < 10; i += 2) {
// yield pages.sendKeys(i);
// yield this.sleep(3000);
// }
yield this.elementByName("Back").click();
yield this.elementByName("TextFields, Uses of UITextField").click();
yield this.elementByClassName("UIATextField").sendKeys("Hello World!\n");
yield this.elementByName("Back").click();
yield this.elementByName("Pickers, Uses of UIDatePicker, UIPickerView").click();
var pickers = yield this.elementsByClassName("UIAPicker");
/*var wheels =*/ yield pickers[0].elementsByClassName("UIAPickerWheel");
// TODO: sendKey to picker is not working
//yield wheels[0].sendKeys("Serena Auroux");
yield this.elementByName("Back").click();
yield this.elementByName("Images, Use of UIImageView").click();
yield this.elementByClassName("UIASlider").sendKeys("0.8");
yield this.sleep(2);
yield this.elementByName("Back").click();
yield this.elementByName("Web, Use of UIWebView").click();
yield this.sleep(3000);
yield this.contexts();
yield this.context("WEBVIEW");
yield this.get("https://www.saucelabs.com");
yield this.context("NATIVE_APP");
yield this.elementByName("Back").click();
console.log(yield this.source());
} catch (e) {
console.log(e);
}
yield this.sleep(3);
yield this.quit();
if (server) server.close();
});
+75
View File
@@ -0,0 +1,75 @@
// This requires node 0.11 and harmony
"use strict";
/* jshint esnext: true */
require("./helpers/setup");
var wd = require("yiewd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("ios simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.remote(serverConfig.host,serverConfig.port,
serverConfig.username, serverConfig.password);
require("./helpers/logging").configure(driver);
before(function (done) {
driver.run(function* () {
var desired = _.clone(require("./helpers/caps").ios71);
desired.app = require("./helpers/apps").iosTestApp;
if (process.env.SAUCE) {
desired.name = 'ios - simple';
desired.tags = ['sample'];
}
yield driver.init(desired);
done();
});
});
after(function () {
driver.run(function* () {
try {
yield driver.quit();
} catch (ign) {
if (process.env.SAUCE) {
yield driver.sauceJobStatus(allPassed);
}
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should compute the sum", function (done) {
driver.run(function* () {
var inputFieldNames = ['IntegerA', 'IntegerB'];
var sum = 0;
for(var i=0; i<inputFieldNames.length; i++) {
var inputEl = yield driver.waitForElementByName(inputFieldNames[i]);
var x = _.random(0,10);
sum += x;
yield inputEl.type('' + x);
yield driver.elementByName('Done').click();
yield driver.sleep(1000);
}
var computeEl = yield driver.elementByAccessibilityId('ComputeSumButton');
yield computeEl.click();
yield driver.sleep(1000);
var answerEl = driver.elementByIosUIAutomation('elements().withName("Answer");');
var answer = yield answerEl.text();
answer.should.equal("" + sum);
done();
});
});
});
@@ -1,62 +0,0 @@
"use strict";
/*
You need to install Chrome first on your emulator (last tested against v30).
(Look for a apk and use 'adb install', or install from Google play. Try first
with an ARM emulator.)
Then run:
node local-android-wd-chrome.js
*/
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var desired = {
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.3',
deviceName: 'Android Emulator',
browserName: 'chrome'
};
// Instantiate a new browser session
var browser = wd.promiseChainRemote("localhost", 4723);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the tests
browser
.init(desired).then(function () {
browser
.get("http://saucelabs.com/test/guinea-pig")
.elementById('i_am_an_id')
.text().should.become("I am a div")
.elementById('comments')
.sendKeys("This is an awesome comment")
.elementById('submit')
.click()
.waitForElementById('your_comments',
wd.asserters.textInclude("This is an awesome comment"))
.text()
.should.eventually.include('awesome')
.fin(function () { return browser.quit(); });
})
.catch(function (err) {
console.log(err);
throw err;
})
.done();
@@ -1,71 +0,0 @@
"use strict";
/*
run:
node local-android-wd-contacts.js
*/
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',
platformName: 'Android',
platformVersion: '4.3',
deviceName: 'Android Emulator',
"app": path.resolve(__dirname, '../..', 'apps/ContactManager/ContactManager.apk'),
"appPackage": "com.android.contacts", // built-in contact app
"appActivity": "activities.PeopleActivity"
};
// Default is for very slow ARM emulator
var TIME_BASE_UNIT = parseInt(process.env.TIME_BASE_UNIT || 5000);
// Instantiate a new browser session
var browser = wd.promiseChainRemote("localhost", 4723);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser
.init(desired).then(function () {
return browser
// add new contact
.elementByName("Add Contact")
.click()
.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')
]);
})
.elementByName("Save")
.click()
.fin(function () {
return browser
.sleep(TIME_BASE_UNIT) // waiting a bit before quitting
.quit();
});
})
.catch(function (err) {
console.log(err);
throw err;
})
.done();
@@ -1,99 +0,0 @@
/* jshint esnext: true */
"use strict";
/*
First you need to install node > 0.11 to run this.
(You may use this https://github.com/visionmedia/n for easy install/switch
between node versions)
Then run:
node --harmony local-android-yiewd-contacts.js
*/
var wd = require("yiewd"),
o_O = require('monocle-js').o_O,
path = require('path');
require('colors');
var desired = {
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.3',
deviceName: 'Android Emulator',
"app": path.resolve(__dirname, '../..', 'apps/ContactManager/ContactManager.apk'),
"appPackage": "com.android.contacts", // built-in contact app
"appActivity": "activities.PeopleActivity"
};
// Default is for very slow ARM emulator
var TIME_BASE_UNIT = parseInt(process.env.TIME_BASE_UNIT || 5000);
var bc = function(t) { return "//android.widget.Button[contains(@text, '" + t + "')]"; };
var ec = "//android.widget.EditText";
var tc = function(t) { return "//android.widget.TextView[contains(@text, '" + t + "')]"; };
var driver = wd.remote('localhost', 4723);
// See whats going on
driver.on('status', function(info) {
console.log(info.cyan);
});
driver.on('command', function(meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
var deleteUser = function(name, timeout) {
return o_O(function*() {
yield driver.waitForElementByXPath(tc(name), timeout).click();
yield driver.elementByName('More options').click();
yield driver.waitForElementByXPath(tc('Delete')).click();
yield driver.elementByXPath(bc('OK'), TIME_BASE_UNIT).click();
})();
};
// Run the testå
driver.run(function*() {
try {
yield this.init(desired);
// TODO: this sleep should not be necessary
yield this.sleep(3000);
// waiting for app initialization
yield this.waitForElementByXPath(tc('Contact Manager'), 10*TIME_BASE_UNIT);
//try to delete contact if it is there
try{
yield deleteUser('John Smith', TIME_BASE_UNIT/10);
} catch(ignore) {}
yield this.waitForElementByXPath(bc('Add Contact'), 2*TIME_BASE_UNIT).click();
// There may be a confirmation stage
try {
yield this.waitForElementByXPath(bc('Keep'), TIME_BASE_UNIT).click();
} catch(ignore) {}
// Adding user
yield this.waitForElementByXPath(ec, 2*TIME_BASE_UNIT);
var ecs = yield this.elementsByXPath(ec);
yield ecs[0].sendKeys("John Smith");
yield ecs[1].sendKeys("(555) 555-5555");
yield ecs[2].sendKeys("john.smith@google.io");
yield this.elementByXPath(bc('Save')).click();
// TODO: The contact manager is crashing right here.
// // Editing user
// yield this.waitForElementByName("Edit", TIME_BASE_UNIT*10); // superslow
// yield this.elementByName("Edit").click();
// yield this.waitForElementByXPath(bc('Add another field'), 2*TIME_BASE_UNIT).click();
// yield this.waitForElementByXPath(tc('Address'), 2*TIME_BASE_UNIT).click();
// yield this.waitForElementByXPath(ec('Address'), 2*TIME_BASE_UNIT).sendKeys("123 Appium Street");
// yield this.elementByXPath(tc('Done')).click();
// // Deleting user
// yield deleteUser('John Smith', 2*TIME_BASE_UNIT);
} catch(e) {
console.log(e);
}
yield this.sleep(Math.ceil(TIME_BASE_UNIT/1000)); // yiewd sleep takes seconds
yield this.quit();
});
@@ -1,64 +0,0 @@
"use strict";
/*
run:
node local-ios-wd-hybrid.js
*/
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var desired = {
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
name: "Appium Hybrid App: with WD",
app: "http://appium.s3.amazonaws.com/WebViewApp6.0.app.zip",
newCommandTimeout: 60
};
// Instantiate a new browser session
var browser = wd.promiseChainRemote("localhost", 4723);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser
.init(desired)
.then(function () {
browser
.context('WEBVIEW')
.windowHandles().then(function (handles) {
handles.should.have.length.above(0);
return browser
.window(handles[0])
.elementById('i_am_an_id')
.text().should.become("I am a div");
})
.context(null)
.catch(function(err) { console.log(err); })
.fin(function () {
return browser
.sleep(3000)
.quit();
});
})
.catch(function (err) {
console.log(err);
throw err;
})
.done();
@@ -1,61 +0,0 @@
"use strict";
/*
run:
node local-ios-wd-safari.js
*/
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var desired = {
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
browserName: "safari",
name: "Appium Safari: with WD",
newCommandTimeout: 60
};
var browser = wd.promiseChainRemote("localhost", 4723);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser
.init(desired)
.then(function () {
browser
.get("http://saucelabs.com/test/guinea-pig")
.waitForElementById('i_am_an_id', 5000)
.text().should.become("I am a div")
.elementById('comments')
.sendKeys("This is an awesome comment")
.elementById('submit')
.click()
.waitForElementById('your_comments',
wd.asserters.textInclude("This is an awesome comment"))
.fin(function () {
return browser
.sleep(3000)
.quit();
});
})
.catch(function (err) {
console.log(err);
throw err;
})
.done();
@@ -1,85 +0,0 @@
/*global it:true, describe:true, before:true, after:true */
"use strict";
/*
1/ Set your sauce credentials (SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables)
2/ npm install mocha -g;
3/ Run:
mocha -R spec sauce-android-mocha-wd-notes.js
*/
var wd = require("wd"),
Q = wd.Q;
require('colors');
var chai = require("chai"),
chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var host = "ondemand.saucelabs.com",
port = 80,
username = process.env.SAUCE_USERNAME,
accessKey = process.env.SAUCE_ACCESS_KEY;
// Big timeout is needed
var timeout = process.env.TIMEOUT || 300000;
var desired = {
browserName: '',
'appium-version': '1.0',
platformName: 'Android',
platformVersion: '4.3',
deviceName: 'Android Emulator',
app: 'http://appium.s3.amazonaws.com/NotesList.apk',
name: 'Sauce Android test',
'appActivity': '.NotesList',
'appPackage': 'com.example.android.notepad'
};
describe('notes app', function() {
this.timeout(timeout);
var browser = null;
before(function(done) {
browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function(info) {
console.log(info.cyan);
});
browser.on('command', function(meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
browser
.init(desired)
.nodeify(done);
});
after(function(done) {
browser
.quit()
.nodeify(done);
});
it('should save a note', function(done) {
browser
.elementByName("New note")
.click()
.sleep(10000)
.elementByClassName('android.widget.TextView')
.sendKeys("This is a new note!")
.elementByName("Save")
.click()
.elementsByClassName("android.widget.TextView")
.then(function(els) {
return Q.all([
els[2].text().should.become("This is a new note!"),
els[2].click()
])
.nodeify(done);
});
});
});
@@ -1,108 +0,0 @@
/*global it:true, describe:true, before:true, after:true */
"use strict";
/*
1/ Set your sauce credentials (SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables)
2/ npm install mocha -g;
3/ Start Sauce Connect
4/ Run:
mocha -R spec sauce-connect-ios-mocha-wd-raw.js
*/
var wd = require("wd"),
Q = wd.Q,
_ = require('underscore');
require('colors');
var chai = require("chai"),
chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var staticServer = require('node-static'),
path = require("path"),
http = require('http'),
assetDir = path.resolve(__dirname, "../../../assets"),
fileServer = new staticServer.Server(assetDir);
// create a local server to host our app
var server = http.createServer(function(req, res) {
req.addListener('end', function() {
fileServer.serve(req, res);
}).resume();
}).listen(8080);
var host = "localhost",
port = 4445,
username = process.env.SAUCE_USERNAME,
accessKey = process.env.SAUCE_ACCESS_KEY;
// Big timeout is needed
var timeout = process.env.TIMEOUT || 300000;
// Browser/app config
var appUrl = 'http://localhost:8080/TestApp6.0.app.zip';
var desired = {
browserName: '',
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
app: appUrl,
name: "Appium: with WD Mocha",
'deviceOrientation': 'portrait',
};
describe('notes app', function() {
this.timeout(timeout);
var browser = null;
var values = [];
before(function(done) {
browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function(info) {
console.log(info.cyan);
});
browser.on('command', function(meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
browser
.init(desired)
.nodeify(done);
});
after(function(done) {
server.close();
browser
.quit()
.nodeify(done);
});
it('should fill two fields with numbers', function(done) {
browser
.elementsByIosUIAutomation('.textFields();').then(function(elems) {
var seq = [];
_(elems).each(function(elem) {
seq.push(function() {
var val = Math.round(Math.random()*10);
values.push(val);
return elem.sendKeys(val);
});
});
return seq.reduce(Q.when, new Q());
})
.elementByIosUIAutomation('.buttons()')
.click()
.elementByClassName('UIAStaticText')
.text().then(function(text) {
var sum = values[0] + values[1];
sum.should.equal(parseInt(text, 10));
})
.nodeify(done);
});
});
@@ -1,90 +0,0 @@
/*global it:true, describe:true, before:true, after:true */
"use strict";
/*
1/ Set your sauce credentials (SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables)
2/ npm install mocha -g;
3/ Run:
mocha -R spec sauce-ios-mocha-raw.js
*/
var wd = require("wd");
var Q = wd.Q;
var _ = require('underscore');
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var host = "ondemand.saucelabs.com",
port = 80,
username = process.env.SAUCE_USERNAME,
accessKey = process.env.SAUCE_ACCESS_KEY;
// Big timeout is needed
var timeout = process.env.TIMEOUT || 300000;
var desired = {
browserName: '',
'appium-version': '1.0',
platformName: 'iOS',
platformVersion: '7.1',
deviceName: 'iPhone Simulator',
app: 'http://appium.s3.amazonaws.com/TestApp6.0.app.zip',
name: "Appium: with WD Mocha",
'deviceOrientation': 'portrait',
};
describe('notes app', function() {
this.timeout(timeout);
var browser = null;
var values = [];
before(function(done) {
browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function(info) {
console.log(info.cyan);
});
browser.on('command', function(meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
browser
.init(desired)
.nodeify(done);
});
after(function(done) {
browser
.quit()
.nodeify(done);
});
it('should fill two fields with numbers', function(done) {
browser
.elementsByIosUIAutomation('.textFields();').then(function(elems) {
var seq = [];
_(elems).each(function(elem) {
seq.push(function() {
var val = Math.round(Math.random()*10);
values.push(val);
return elem.sendKeys(val);
});
});
return seq.reduce(Q.when, new Q());
})
.elementByIosUIAutomation('.buttons()')
.click()
.elementByClassName('UIAStaticText')
.text().then(function(text) {
var sum = values[0] + values[1];
sum.should.equal(parseInt(text, 10));
})
.nodeify(done);
});
});
@@ -0,0 +1,60 @@
"use strict";
require("./helpers/setup");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('./helpers/appium-servers');
describe("selendroid simple", function () {
this.timeout(300000);
var driver;
var allPassed = true;
before(function () {
var serverConfig = process.env.SAUCE ?
serverConfigs.sauce : serverConfigs.local;
driver = wd.promiseChainRemote(serverConfig);
require("./helpers/logging").configure(driver);
var desired = _.clone(require("./helpers/caps").selendroid16);
desired.app = require("./helpers/apps").androidApiDemos;
if (process.env.SAUCE) {
desired.name = 'selendroid - simple';
desired.tags = ['sample'];
}
return driver
.init(desired)
.setImplicitWaitTimeout(3000);
});
after(function () {
return driver
.quit()
.finally(function () {
if (process.env.SAUCE) {
return driver.sauceJobStatus(allPassed);
}
});
});
afterEach(function () {
allPassed = allPassed && this.currentTest.state === 'passed';
});
it("should find elements", function () {
return driver
.waitForElementByName('Animation')
.text().should.become('Animation')
.elementByClassName('android.widget.TextView')
.text().should.become('API Demos')
.elementByName('App').click()
.waitForElementByXPath('//TextView[@name=\'Action Bar\']')
.elementsByClassName('android.widget.TextView')
.should.eventually.have.length.above(20)
.back()
.sleep(3000)
.waitForElementByName('Animation', 5000, 500)
.text().should.become('Animation');
});
});