exports.mobileRotation = function (req, res) {
req.body = _.defaults(req.body, {
x: 0.5
, y: 0.5
, radius: 0.5
, rotation: 3.14159265359
, touchCount: 2
, duration: 1
, element: null
});
var element = req.body.element
, duration = req.body.duration
, x = req.body.x
, y = req.body.y
, radius = req.body.radius
, touchCount = req.body.touchCount
, rotation = req.body.rotation;
req.device.rotate(x, y, radius, rotation, duration, touchCount, element, getResponseHandler(req, res));
};
exports.mobilePinchClose = function (req, res) {
req.body = _.defaults(req.body, {
startX: 0.5
, startY: 0.5
, endX: 0.5
, endY: 0.5
, duration: 0.8
, percent: 200
, steps: 50
, element: null
});
var element = req.body.element
, duration = req.body.duration
, startX = req.body.startX
, startY = req.body.startY
, endX = req.body.endX
, endY = req.body.endY
, percent = req.body.percent
, steps = req.body.steps;
req.device.pinchClose(startX, startY, endX, endY, duration, percent, steps, element, getResponseHandler(req, res));
};
exports.mobilePinchOpen = function (req, res) {
req.body = _.defaults(req.body, {
startX: 0.5
, startY: 0.5
, endX: 0.5
, endY: 0.5
, duration: 0.8
, percent: 200
, steps: 50
, element: null
});
var element = req.body.element
, duration = req.body.duration
, startX = req.body.startX
, startY = req.body.startY
, endX = req.body.endX
, endY = req.body.endY
, percent = req.body.percent
, steps = req.body.steps;
req.device.pinchOpen(startX, startY, endX, endY, duration, percent, steps, element, getResponseHandler(req, res));
};
exports.mobileScrollTo = function (req, res) {
logCustomDeprecationWarning('mobile method', 'scrollTo',
"scrollTo will be removed in a future version of appium");
req.body = _.defaults(req.body, {
element: null
, text: null
, direction: "vertical"
});
var element = req.body.element
, text = req.body.text
, direction = req.body.direction;
req.device.scrollTo(element, text, direction, getResponseHandler(req, res));
};
exports.mobileScroll = function (req, res) {
req.body = _.defaults(req.body, {
element: null
, direction: "down"
});
var direction = req.body.direction.toString().toLowerCase()
, element = req.body.element;
if (!_.contains(['up', 'left', 'right', 'down'], direction)) {
return respondError(req, res, status.codes.UnknownCommand.code,
new Error("Direction " + direction + " is not valid for scroll"));
}
req.device.scroll(element, direction, getResponseHandler(req, res));
};
exports.mobileShake = function (req, res) {
req.device.shake(getResponseHandler(req, res));
};
exports.hideKeyboard = function (req, res) {
var key = req.body.key || req.body.keyName;
var strategy = req.body.strategy ||
(key ? 'pressKey' : 'default');
req.device.hideKeyboard(strategy, key, getResponseHandler(req, res));
};
exports.clear = function (req, res) {
var elementId = req.params.elementId;
req.device.clear(elementId, getResponseHandler(req, res));
};
exports.getText = function (req, res) {
var elementId = req.params.elementId;
req.device.getText(elementId, getResponseHandler(req, res));
};
exports.getName = function (req, res) {
var elementId = req.params.elementId;
req.device.getName(elementId, getResponseHandler(req, res));
};
exports.getAttribute = function (req, res) {
var elementId = req.params.elementId
, attributeName = req.params.name;
req.device.getAttribute(elementId, attributeName, getResponseHandler(req, res));
};
exports.getCssProperty = function (req, res) {
var elementId = req.params.elementId
, propertyName = req.params.propertyName;
req.device.getCssProperty(elementId, propertyName, getResponseHandler(req, res));
};
exports.getLocation = function (req, res) {
logCustomDeprecationWarning('location', 'getLocation', "location will be removed in a future version of Appium, please use location_in_view");
exports.getLocationInView(req, res);
};
exports.getLocationInView = function (req, res) {
var elementId = req.params.elementId;
req.device.getLocation(elementId, getResponseHandler(req, res));
};
exports.getSize = function (req, res) {
var elementId = req.params.elementId;
req.device.getSize(elementId, getResponseHandler(req, res));
};
exports.getWindowSize = function (req, res) {
var windowHandle = req.params.windowhandle;
req.device.getWindowSize(windowHandle, getResponseHandler(req, res));
};
exports.maximizeWindow = function (req, res) {
// noop
respondSuccess(req, res);
};
exports.getPageIndex = function (req, res) {
var elementId = req.params.elementId;
req.device.getPageIndex(elementId, getResponseHandler(req, res));
};
exports.pressKeyCode = function (req, res) {
req.body = _.defaults(req.body, {
keycode: null
, metastate: null
});
var keycode = req.body.keycode
, metastate = req.body.metastate;
req.device.pressKeyCode(keycode, metastate, getResponseHandler(req, res));
};
exports.longPressKeyCode = function (req, res) {
req.body = _.defaults(req.body, {
keycode: null
, metastate: null
});
var keycode = req.body.keycode
, metastate = req.body.metastate;
req.device.longPressKeyCode(keycode, metastate, getResponseHandler(req, res));
};
exports.keyevent = function (req, res) {
req.body = _.defaults(req.body, {
keycode: null
, metastate: null
});
var keycode = req.body.keycode
, metastate = req.body.metastate;
req.device.keyevent(keycode, metastate, getResponseHandler(req, res));
};
exports.back = function (req, res) {
req.device.back(getResponseHandler(req, res));
};
exports.forward = function (req, res) {
req.device.forward(getResponseHandler(req, res));
};
exports.refresh = function (req, res) {
req.device.refresh(getResponseHandler(req, res));
};
exports.keys = function (req, res) {
var keys = req.body.value.join('');
req.device.keys(keys, getResponseHandler(req, res));
};
exports.frame = function (req, res) {
var frame = req.body.id;
req.device.frame(frame, getResponseHandler(req, res));
};
exports.elementDisplayed = function (req, res) {
var elementId = req.params.elementId;
req.device.elementDisplayed(elementId, getResponseHandler(req, res));
};
exports.elementEnabled = function (req, res) {
var elementId = req.params.elementId;
req.device.elementEnabled(elementId, getResponseHandler(req, res));
};
exports.elementSelected = function (req, res) {
var elementId = req.params.elementId;
req.device.elementSelected(elementId, getResponseHandler(req, res));
};
exports.getPageSource = function (req, res) {
req.device.getPageSource(getResponseHandler(req, res));
};
exports.getAlertText = function (req, res) {
req.device.getAlertText(getResponseHandler(req, res));
};
exports.setAlertText = function (req, res) {
var text = req.body.text;
req.device.setAlertText(text, getResponseHandler(req, res));
};
exports.postAcceptAlert = function (req, res) {
req.device.postAcceptAlert(getResponseHandler(req, res));
};
exports.postDismissAlert = function (req, res) {
req.device.postDismissAlert(getResponseHandler(req, res));
};
exports.implicitWait = function (req, res) {
var ms = req.body.ms;
req.device.implicitWait(ms, getResponseHandler(req, res));
};
exports.asyncScriptTimeout = function (req, res) {
var ms = req.body.ms;
req.device.asyncScriptTimeout(ms, getResponseHandler(req, res));
};
exports.pageLoadTimeout = function (req, res) {
var ms = req.body.ms;
req.device.pageLoadTimeout(ms, getResponseHandler(req, res));
};
exports.timeouts = function (req, res) {
var timeoutType = req.body.type
, ms = req.body.ms;
if (checkMissingParams(req, res, {type: timeoutType, ms: ms})) {
if (timeoutType === "implicit") {
exports.implicitWait(req, res);
} else if (timeoutType === "script") {
exports.asyncScriptTimeout(req, res);
} else if (timeoutType === "command") {
var secs = parseInt(ms, 10) / 1000;
req.appium.setCommandTimeout(secs, getResponseHandler(req, res));
} else if (timeoutType === "page load") {
exports.pageLoadTimeout(req, res);
} else {
respondError(req, res, status.codes.UnknownCommand.code,
new Error("Invalid timeout '" + timeoutType + "'"));
}
}
};
exports.setOrientation = function (req, res) {
var orientation = req.body.orientation;
req.device.setOrientation(orientation, getResponseHandler(req, res));
};
exports.setLocation = function (req, res) {
if (req.body.latitude || req.body.longitude) {
logCustomDeprecationWarning('geolocation', 'wrongbody',
"Use of the set location method with the latitude and longitude " +
"params as top-level JSON params is deprecated and will be removed. " +
"Please update your client library to use a method that conforms " +
"to the spec");
}
var location = req.body.location || {};
var latitude = location.latitude || req.body.latitude
, longitude = location.longitude || req.body.longitude
, altitude = location.altitude || req.body.altitude || null;
req.device.setLocation(latitude, longitude, altitude, null, null, null, null, getResponseHandler(req, res));
};
exports.getOrientation = function (req, res) {
req.device.getOrientation(getResponseHandler(req, res));
};
exports.getScreenshot = function (req, res) {
req.device.getScreenshot(getResponseHandler(req, res));
};
exports.moveTo = function (req, res) {
req.body = _.defaults(req.body, {
xoffset: 0.5
, yoffset: 0.5
});
var xoffset = req.body.xoffset
, yoffset = req.body.yoffset
, element = req.body.element;
req.device.moveTo(element, xoffset, yoffset, getResponseHandler(req, res));
};
exports.clickCurrent = function (req, res) {
var button = req.body.button || 0;
req.device.clickCurrent(button, getResponseHandler(req, res));
};
exports.pickAFlickMethod = function (req, res) {
if (typeof req.body.xSpeed !== "undefined" || typeof req.body.xspeed !== "undefined") {
exports.flick(req, res);
} else {
exports.flickElement(req, res);
}
};
exports.flick = function (req, res) {
var swipe = req.body.swipe
, xSpeed = req.body.xSpeed
, ySpeed = req.body.ySpeed
, element = req.body.element;
if (typeof xSpeed === "undefined") {
xSpeed = req.body.xspeed;
}
if (typeof ySpeed === "undefined") {
ySpeed = req.body.yspeed;
}
if (checkMissingParams(req, res, {xSpeed: xSpeed, ySpeed: ySpeed})) {
if (element) {
exports.flickElement(req, res);
} else {
req.device.fakeFlick(xSpeed, ySpeed, swipe, getResponseHandler(req, res));
}
}
};
转载于:https://blog.51cto.com/10988776/1727934