Skip to content

Commit 21d5d60

Browse files
update double tap gesture and pan
1 parent 8e8922f commit 21d5d60

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

lib/appium-driver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class AppiumDriver {
262262
prepareApp(args);
263263
if (!args.device) {
264264
if (args.isAndroid) {
265-
args.device = DeviceManager.getDefaultDevice(args, sessionInfo.capabilities.desired.deviceName, sessionInfo.capabilities.deviceUDID.replace("emulator-", ""), sessionInfo.capabilities.deviceUDID.includes("emulator") ? DeviceType.EMULATOR : DeviceType.SIMULATOR, sessionInfo.capabilities.desired.platformVersion || sessionInfo.capabilities.platformVersion);
265+
args.device = DeviceManager.getDefaultDevice(args, sessionInfo.capabilities.desired.deviceName, sessionInfo.capabilities.deviceUDID.replace("emulator-", ""), sessionInfo.capabilities.deviceUDID.includes("emulator") ? DeviceType.EMULATOR : DeviceType.SIMULATOR, sessionInfo.capabilities.deviceApiLevel || sessionInfo.capabilities.platformVersion);
266266
} else {
267267
args.device = DeviceManager.getDefaultDevice(args);
268268
}

lib/appium-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class AppiumServer {
126126

127127
private startAppiumServer(logLevel: string, isSauceLab: boolean) {
128128
const startingServerArgs: Array<string> = isSauceLab ? ["--log-level", logLevel] : ["-p", this.port.toString(), "--log-level", logLevel];
129-
if (this._args.isAndroid && this._args.ignoreDeviceController && !this._args.isSauceLab) {
129+
if (this._args.isAndroid) {
130130
this._args.relaxedSecurity ? startingServerArgs.push("--relaxed-security") : console.log("'relaxedSecurity' is not enabled!\nTo enabled it use '--relaxedSecurity'!");
131131
}
132132

lib/device-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class DeviceManager implements IDeviceManager {
171171
type: type,
172172
platform: args.appiumCaps.platformName.toLowerCase(),
173173
token: token,
174-
apiLevel: platformVersion || args.appiumCaps.platformVersion,
174+
apiLevel: platformVersion || args.appiumCaps.deviceApiLevel || args.appiumCaps.platformVersion,
175175
config: { "density": args.appiumCaps.density, "offsetPixels": args.appiumCaps.offsetPixels }
176176
}
177177

lib/ui-element.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export declare class UIElement {
3333
* @experimental
3434
* Double tap on element
3535
*/
36-
doubleTap(): Promise<any>;
36+
doubleTap(offset?: {
37+
x: number;
38+
y: number;
39+
}): Promise<any>;
3740
longPress(duration: number): Promise<void>;
3841
/**
3942
* Get location of element
@@ -178,10 +181,10 @@ export declare class UIElement {
178181
/**
179182
*@experimental
180183
* Pan element with specific offset
181-
* @param points where the finger should move to.
184+
* @param offsets where the finger should move to.
182185
* @param initPointOffset element.getRectangle() is used as start point. In case some additional offset should be provided use this param.
183186
*/
184-
pan(points: {
187+
pan(offsets: {
185188
x: number;
186189
y: number;
187190
}[], initPointOffset?: {

lib/ui-element.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,22 @@ export class UIElement {
6767
* @experimental
6868
* Double tap on element
6969
*/
70-
public async doubleTap() {
70+
public async doubleTap(offset: { x: number, y: number } = { x: 0, y: 0 }) {
7171
if (this._args.isAndroid) {
7272
// hack double tap for android
73-
let action = new this._wd.TouchAction(this._driver);
7473
const rect = await this.getRectangle();
75-
action.press({ x: rect.x, y: rect.y }).release().perform();
76-
action.press({ x: rect.x, y: rect.y }).release().perform();
77-
await action.perform();
74+
75+
if (`${this._args.device.apiLevel}`.startsWith("29")
76+
|| `${this._args.device.apiLevel}`.startsWith("9.")) {
77+
const offsetPoint = { x: (rect.x + offset.x), y: (rect.y + offset.y) };
78+
await adbShellCommand(this._driver, "input", ["tap", `${offsetPoint.x} ${offsetPoint.y}`]);
79+
await adbShellCommand(this._driver, "input", ["tap", `${offsetPoint.x} ${offsetPoint.y}`]);
80+
} else {
81+
let action = new this._wd.TouchAction(this._driver);
82+
action.press({ x: rect.x, y: rect.y }).release().perform();
83+
action.press({ x: rect.x, y: rect.y }).release().perform();
84+
await action.perform();
85+
}
7886
} else {
7987
// this works only for ios, otherwise it throws error
8088
return await this._driver.execute('mobile: doubleTap', { element: this._element.value });
@@ -518,18 +526,19 @@ export class UIElement {
518526
/**
519527
*@experimental
520528
* Pan element with specific offset
521-
* @param points where the finger should move to.
529+
* @param offsets where the finger should move to.
522530
* @param initPointOffset element.getRectangle() is used as start point. In case some additional offset should be provided use this param.
523531
*/
524-
public async pan(points: { x: number, y: number }[], initPointOffset: { x: number, y: number } = { x: 0, y: 0 }) {
532+
public async pan(offsets: { x: number, y: number }[], initPointOffset: { x: number, y: number } = { x: 0, y: 0 }) {
525533
logInfo("Start pan gesture!");
526534
const rect = await this.getRectangle();
527535
const action = new this._wd.TouchAction(this._driver);
528-
await action.press({ x: rect.x + initPointOffset.x, y: rect.y + initPointOffset.y }).wait(100)
529-
if (points.length > 1) {
530-
for (let index = 1; index < points.length; index++) {
531-
const element = points[index];
532-
action.moveTo({ x: element.x, y: element.y });
536+
await action.press({ x: rect.x + initPointOffset.x, y: rect.y + initPointOffset.y });
537+
await this.doubleTap();
538+
if (offsets.length > 1) {
539+
for (let index = 1; index < offsets.length; index++) {
540+
const p = offsets[index];
541+
action.moveTo({ x: rect.x + p.x, y: rect.y + p.y });
533542
}
534543
}
535544

0 commit comments

Comments
 (0)