Skip to content

Commit ddcf4bc

Browse files
authored
fix: send mobile scroll distance only for direction strategy (#2741)
* fix: send mobile scroll distance only for direction strategy * Update gesture.ts
1 parent 68537e8 commit ddcf4bc

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

docs/reference/execute-methods.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ Name | Type | Required | Description | Example
11641164
elementId ("element" prior to Appium v 1.22) | string | no | The internal element identifier (as hexadecimal hash string) to scroll on (e.g. the container). The active application element will be used instead if this parameter is not provided. | fe50b60b-916d-420b-8728-ee2072ec53eb
11651165
name | string | no | The accessibility id of the child element, to which scrolling is performed. The same result can be achieved by setting _predicateString_ argument to 'name == accessibilityId'. Has no effect if _elementId_ is not a container | cell12
11661166
direction | Either 'up', 'down', 'left' or 'right' | yes | The main difference from [swipe](#mobile-swipe) call with the same argument is that _scroll_ will try to move the current viewport exactly to the next/previous page (the term "page" means the content, which fits into a single device screen) | down
1167+
distance | number | no | A ratio of the screen height. For example, _1.0_ means scrolling one full screen height. Has no effect if _direction_ is not set. | 0.6
11671168
predicateString | string | no | The NSPredicate locator of the child element, to which the scrolling should be performed. Has no effect if _elementId_ is not a container | label == "foo"
11681169
toVisible | boolean | no | If set to _true_ then asks to scroll to the first visible _elementId_ in the parent container. Has no effect if _elementId_ is not set | true
11691170

lib/commands/gesture.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ export async function mobileScroll(
184184
);
185185
}
186186
params.direction = direction;
187+
// we can also optionally pass a distance which appears to be a ratio of
188+
// screen height, so 1.0 means a full screen's worth of scrolling
189+
if (!_.isNil(distance)) {
190+
params.distance = distance;
191+
}
187192
} else if (predicateString) {
188193
params.predicateString = predicateString;
189194
} else if (toVisible) {
@@ -194,11 +199,6 @@ export async function mobileScroll(
194199
'Specify one of these',
195200
);
196201
}
197-
// we can also optionally pass a distance which appears to be a ratio of
198-
// screen height, so 1.0 means a full screen's worth of scrolling
199-
if (!_.isNil(distance)) {
200-
params.distance = distance;
201-
}
202202
const endpoint = elementId
203203
? `/wda/element/${util.unwrapElement(elementId)}/scroll`
204204
: '/wda/scroll';

test/unit/commands/gesture-specs.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ describe('gesture commands', function () {
7171
predicateString: 'something',
7272
});
7373
});
74+
it('should pass distance only for direction strategy', async function () {
75+
mockDriver
76+
.expects('proxyCommand')
77+
.once()
78+
.withExactArgs('/wda/element/4/scroll', 'POST', {direction: 'down', distance: 0.6});
79+
await driver.execute('mobile: scroll', {
80+
element: 4,
81+
direction: 'down',
82+
distance: 0.6,
83+
});
84+
});
85+
it('should ignore distance for non-direction strategy', async function () {
86+
mockDriver
87+
.expects('proxyCommand')
88+
.once()
89+
.withExactArgs('/wda/element/4/scroll', 'POST', {name: 'something'});
90+
await driver.execute('mobile: scroll', {
91+
element: 4,
92+
name: 'something',
93+
distance: 0.6,
94+
});
95+
});
7496
});
7597

7698
describe('swipe', function () {

0 commit comments

Comments
 (0)