Skip to content

Commit 29d9f03

Browse files
additional logging
1 parent f35d3e2 commit 29d9f03

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
@@ -166,15 +166,15 @@ export declare class UIElement {
166166
* Swipe element left/right
167167
* @param direction
168168
*/
169-
swipe(direction: "up" | "down" | "left" | "right"): Promise<void>;
169+
swipe(direction: Direction): Promise<void>;
170170
/**
171171
* Drag element with specific offset
172172
* @experimental
173173
* @param direction
174174
* @param yOffset
175175
* @param xOffset - default value 0
176176
*/
177-
drag(direction: Direction, yOffset: number, xOffset?: number): Promise<void>;
177+
drag(direction: Direction, yOffset: number, xOffset?: number, duration?: number): Promise<void>;
178178
/**
179179
*@experimental
180180
* Pan element with specific offset

lib/ui-element.ts

+8-14
Original file line numberDiff line numberDiff line change
@@ -452,26 +452,17 @@ export class UIElement {
452452
* Swipe element left/right
453453
* @param direction
454454
*/
455-
public async swipe(direction: "up" | "down" | "left" | "right") {
456-
logInfo(`Swipe direction: `, direction);
455+
public async swipe(direction: Direction) {
456+
logInfo(`Swipe direction: `, Direction[direction]);
457457
if (this._args.isIOS) {
458458
await this._driver
459459
.execute('mobile: scroll', {
460460
element: <any>this._element.value,
461-
direction: direction
461+
direction: Direction[direction]
462462
});
463463
} else {
464464
try {
465-
let scrollDirection = Direction.up;
466-
switch (direction) {
467-
case "down": scrollDirection = Direction.down;
468-
break;
469-
case "left": scrollDirection = Direction.left;
470-
break;
471-
case "right": scrollDirection = Direction.right;
472-
break;
473-
}
474-
await this.scroll(scrollDirection);
465+
await this.scroll(direction);
475466
} catch (error) {
476467
console.log("", error);
477468
}
@@ -486,13 +477,16 @@ export class UIElement {
486477
* @param yOffset
487478
* @param xOffset - default value 0
488479
*/
489-
public async drag(direction: Direction, yOffset: number, xOffset: number = 0) {
480+
public async drag(direction: Direction, yOffset: number, xOffset: number = 0, duration?: number) {
481+
direction = direction === Direction.up ? Direction.down : Direction.up;
482+
490483
const location = await this.location();
491484

492485
const x = location.x === 0 ? 10 : location.x;
493486
const y = location.y === 0 ? 10 : location.y;
494487

495488
const endPoint = calculateOffset(direction, y, yOffset, x, xOffset, this._args.isIOS);
489+
duration = duration || endPoint.duration;
496490

497491
if (this._args.isAndroid) {
498492
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)