Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then(() => {
let action = new wd.TouchAction(driver);
action = action.tap({x, y});
if (profile.platformName === "iOS") {
action = action.release(); // Android doesn't like this much
}
action = action.wait({ms:1000});
return action.perform();
})
.then(switchToWebViewContext);
let res = {};
if (!_.isArray(args)) {
args = [args];
}
if (elementId) {
// Give the cached element a variable name (el1, el2, el3,...) the first time it's used
cachedEl = this.elementCache[elementId];
if (!cachedEl.variableName && cachedEl.variableType === 'string') {
cachedEl.variableName = `el${this.elVariableCounter++}`;
}
res = await cachedEl.el[methodName].apply(cachedEl.el, args);
} else {
// Specially handle the tap and swipe method
if (methodName === SCREENSHOT_INTERACTION_MODE.TAP) {
res = await (new wd.TouchAction(this.driver))
.tap({x: args[0], y: args[1]})
.perform();
} else if (methodName === SCREENSHOT_INTERACTION_MODE.SWIPE) {
const [startX, startY, endX, endY] = args;
res = await (new wd.TouchAction(this.driver))
.press({x: startX, y: startY})
.wait(500)
.moveTo({x: endX, y: endY})
.release()
.perform();
} else if (methodName !== 'source' && methodName !== 'screenshot') {
res = await this.driver[methodName].apply(this.driver, args);
}
}
// Give the source/screenshot time to change before taking the screenshot
it('should long press on an element with duration through press-wait-release', async function () {
let el = await driver.elementByAccessibilityId(BTN_OK_CNCL);
let action = new wd.TouchAction(driver);
action.press({el}).wait(1200).release();
await action.perform();
await exitModal('Cancel');
});
it('should long press on an element with duration through pressOpts.duration', async function () {
async function doZoom () {
let el = await driver.elementByClassName('XCUIElementTypeApplication');
let thumb = new wd.TouchAction(driver);
thumb.press({el, x: 100, y: 0}).moveTo({el, x: 50, y: 0}).release();
let foreFinger = new wd.TouchAction(driver);
foreFinger.press({el, x: 100, y: 0}).moveTo({el, x: 105, y: 0}).release();
let zoom = new wd.MultiAction(driver);
zoom.add(thumb, foreFinger);
await zoom.perform();
}
await doZoom();
async function scrollUpUntil(driver, conditionFn) {
for (let _ of Array(10)) {
let action = new wd.TouchAction(driver);
action
.press({x: 600, y: 600})
.wait(200)
.moveTo({x: 600, y: 1100})
.release();
await action.perform();
await driver.sleep(300);
if (await conditionFn()) return;
}
}
var drawLine =function(x1, y1, x2, y2){
var line = (new TouchAction(driver))
.press({x:x1,y:y1})
.moveTo({x:x2, y:y2})
.release();
driver.performTouchAction(line);
}
]).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));
};
.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})
var arcAction = function(start, end) {
var cos = Math.cos;
var sin = Math.sin;
var theta = start;
var prev = {x: h+r*cos(theta), y: k+r*sin(theta)}
var action = new TouchAction(driver);
action.press(prev);
for (; theta < end; theta+=2*pi/100) {
var next = {x: h+r*cos(theta), y: k+r*sin(theta)}
var offset = {x: next.x-prev.x, y: next.y-prev.y}
action.moveTo(offset);
prev = next;
}
action.release();
return action;
}
.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})