Skip to content

Commit cc5b109

Browse files
additional logging
1 parent b18373e commit cc5b109

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

lib/direction.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export declare const enum Direction {
1+
export declare enum Direction {
22
down = 0,
33
up = 1,
44
left = 2,

lib/direction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const enum Direction {
1+
export enum Direction {
22
down,
33
up,
44
left,

lib/ui-element.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ export declare class UIElement {
163163
* Swipe element left/right
164164
* @param direction
165165
*/
166-
swipe(direction: "up" | "down" | "left" | "right"): Promise<void>;
166+
swipe(direction: Direction): Promise<void>;
167167
/**
168168
* Drag element with specific offset
169169
* @experimental
170170
* @param direction
171171
* @param yOffset
172172
* @param xOffset - default value 0
173173
*/
174-
drag(direction: Direction, yOffset: number, xOffset?: number): Promise<void>;
174+
drag(direction: Direction, yOffset: number, xOffset?: number, duration?: number): Promise<void>;
175175
/**
176176
*@experimental
177177
* Pan element with specific offset

lib/ui-element.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -448,26 +448,17 @@ export class UIElement {
448448
* Swipe element left/right
449449
* @param direction
450450
*/
451-
public async swipe(direction: "up" | "down" | "left" | "right") {
452-
logInfo(`Swipe direction: `, direction);
451+
public async swipe(direction: Direction) {
452+
logInfo(`Swipe direction: `, Direction[direction]);
453453
if (this._args.isIOS) {
454454
await this._driver
455455
.execute('mobile: scroll', {
456456
element: <any>this._element.value,
457-
direction: direction
457+
direction: Direction[direction]
458458
});
459459
} else {
460460
try {
461-
let scrollDirection = Direction.up;
462-
switch (direction) {
463-
case "down": scrollDirection = Direction.down;
464-
break;
465-
case "left": scrollDirection = Direction.left;
466-
break;
467-
case "right": scrollDirection = Direction.right;
468-
break;
469-
}
470-
await this.scroll(scrollDirection);
461+
await this.scroll(direction);
471462
} catch (error) {
472463
console.log("", error);
473464
}
@@ -482,13 +473,16 @@ export class UIElement {
482473
* @param yOffset
483474
* @param xOffset - default value 0
484475
*/
485-
public async drag(direction: Direction, yOffset: number, xOffset: number = 0) {
476+
public async drag(direction: Direction, yOffset: number, xOffset: number = 0, duration?: number) {
477+
direction = direction === Direction.up ? Direction.down : Direction.up;
478+
486479
const location = await this.location();
487480

488481
const x = location.x === 0 ? 10 : location.x;
489482
const y = location.y === 0 ? 10 : location.y;
490483

491484
const endPoint = calculateOffset(direction, y, yOffset, x, xOffset, this._args.isIOS);
485+
duration = duration || endPoint.duration;
492486

493487
if (this._args.isAndroid) {
494488
let action = new this._wd.TouchAction(this._driver);

lib/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,10 @@ export function calculateOffset(direction, y: number, yOffset: number, x: number
420420
if (yOffset < xOffset) {
421421
duration = Math.abs(xOffset) * speed;
422422
}
423-
// }
424-
logInfo("Start point point: ", new Point(x, y));
423+
424+
logInfo("Start point: ", new Point(x, y));
425425
logInfo("End point: ", new Point(xEnd, yEnd));
426-
logInfo("Scrolling speed point: ", duration);
426+
logInfo("Scrolling speed: ", duration);
427427

428428
return {
429429
startPoint: new Point(x, y),

0 commit comments

Comments
 (0)