sample code update

This commit is contained in:
sebv
2014-07-01 19:42:53 +08:00
parent 19982c2186
commit b1f8dbddcb
2 changed files with 99 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
"use strict";
var wd = require('wd');
var wd = require('wd'),
Q = require('q');
exports.swipe = function (opts) {
var action = new wd.TouchAction();
@@ -11,3 +12,45 @@ exports.swipe = function (opts) {
.release();
return this.performTouchAction(action);
};
exports.pinch = function (el) {
return Q.all([
el.getSize(),
el.getLocation(),
]).then(function (res) {
var size = res[0];
var loc = res[1];
var center = {
x: loc.x + size.width / 2,
y: loc.y + size.height / 2
};
var a1 = new wd.TouchAction(this);
a1.press({el: el, x: center.x, y: center.y - 100}).moveTo({el: el}).release();
var a2 = new wd.TouchAction(this);
a2.press({el: el, x: center.x, y: center.y + 100}).moveTo({el: el}).release();
var m = new wd.MultiAction(this);
m.add(a1, a2);
return m.perform();
}.bind(this));
};
exports.zoom = function (el) {
return Q.all([
this.getWindowSize(),
this.getLocation(el),
]).then(function (res) {
var size = res[0];
var loc = res[1];
var center = {
x: loc.x + size.width / 2,
y: loc.y + size.height / 2
};
var a1 = new wd.TouchAction(this);
a1.press({el: el}).moveTo({el: el, x: center.x, y: center.y - 100}).release();
var a2 = new wd.TouchAction(this);
a2.press({el: el}).moveTo({el: el, x: center.x, y: center.y + 100}).release();
var m = new wd.MultiAction(this);
m.add(a1, a2);
return m.perform();
}.bind(this));
};

View File

@@ -8,6 +8,12 @@ var wd = require("wd"),
serverConfigs = require('./helpers/appium-servers');
wd.addPromiseChainMethod('swipe', actions.swipe);
wd.addPromiseChainMethod('pinch', actions.pinch);
wd.addElementPromiseChainMethod('pinch',
function () { return this.browser.pinch(this); });
wd.addPromiseChainMethod('zoom', actions.zoom);
wd.addElementPromiseChainMethod('zoom',
function () { return this.browser.zoom(this); });
describe("ios actions", function () {
this.timeout(300000);
@@ -109,4 +115,53 @@ describe("ios actions", function () {
endX: 0.5, endY: loc.y, duration: 800 });
});
});
it("should pinch", function () {
return driver
.waitForElementByName('Test Gesture', 5000).click()
.sleep(1000)
.elementByName('OK').click()
.sleep(1000)
.elementByXPath('//UIAMapView')
.then(function (el) {
return driver.pinch(el);
});
});
it("should pinch el", function () {
return driver
.waitForElementByName('Test Gesture', 5000).click()
.sleep(1000)
.elementByName('OK').click()
.sleep(1000)
.elementByXPath('//UIAMapView')
.then(function (el) {
return el.pinch();
});
});
it("should zoom", function () {
return driver
.waitForElementByName('Test Gesture', 5000).click()
.sleep(1000)
.elementByName('OK').click()
.sleep(1000)
.elementByXPath('//UIAMapView')
.then(function (el) {
return driver.zoom(el);
});
});
it.only("should zoom el", function () {
return driver
.waitForElementByName('Test Gesture', 5000).click()
.sleep(1000)
.elementByName('OK').click()
.sleep(1000)
.elementByXPath('//UIAMapView')
.then(function (el) {
return el.zoom();
});
});
});