Skip to content

Commit

Permalink
add ability to scroll ios views
Browse files Browse the repository at this point in the history
this works on ios7!
  • Loading branch information
jlipps committed Feb 14, 2014
1 parent fc3ba19 commit d2af796
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/gestures.md
Expand Up @@ -79,6 +79,7 @@ In the case of these new mobile methods, `script` must be one of:
* `mobile: flick`
* `mobile: swipe`
* `mobile: scrollTo`
* `mobile: scroll`
* `mobile: shake`
(The `mobile:` prefix allows us to route these requests to the appropriate endpoint).

Expand Down Expand Up @@ -193,6 +194,10 @@ In these examples, note that the element parameter is always optional.

### Swipe

*Note*: Swiping is unfortunately broken in iOS7, because of a bug in Apple's
frameworks. For iOS7, see `mobile: scroll` as a workaround that works for most
cases.

* **WD.js:**

```js
Expand Down Expand Up @@ -222,6 +227,26 @@ In these examples, note that the element parameter is always optional.
js.executeScript("mobile: swipe", swipeObject);
```

### Scroll

* **WD.js:**

```js
// scroll the view down
driver.execute("mobile: scroll", [{direction: 'down'}], function(err) {
// continue testing
});
```

* **Java:**

```java
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> scrollObject = new HashMap<String, Double>();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
```

### Slider

* **Java**
Expand Down
4 changes: 4 additions & 0 deletions lib/devices/android/android-controller.js
Expand Up @@ -522,6 +522,10 @@ androidController.scrollTo = function (elementId, text, cb) {
this.proxy(["element:scrollTo", opts], cb);
};

androidController.scroll = function (direction, cb) {
cb(new NotYetImplementedError(), null);
};

androidController.shake = function (cb) {
cb(new NotYetImplementedError(), null);
};
Expand Down
5 changes: 5 additions & 0 deletions lib/devices/ios/ios-controller.js
Expand Up @@ -1052,6 +1052,11 @@ iOSController.scrollTo = function (elementId, text, cb) {
this.proxy(command, cb);
};

iOSController.scroll = function (direction, cb) {
var command = "au.scrollFirstView('" + direction + "')";
this.proxy(command, cb);
};

iOSController.shake = function (cb) {
this.proxy("au.shake()", cb);
};
Expand Down
27 changes: 27 additions & 0 deletions lib/devices/ios/uiauto/appium/app.js
Expand Up @@ -640,6 +640,33 @@ $.extend(au, {
};
}

, scrollFirstView: function (direction) {
var viewRes = this.getElementByType('scrollview');
console.log(JSON.stringify(viewRes));
var doScroll = function (elId) {
var el = this.getElement(elId);
var method = 'scroll' + direction[0].toUpperCase() + direction.slice(1);
el[method]();
return {
status: codes.Success.code,
value: true
};
}.bind(this);

if (viewRes.status === codes.Success.code) {
return doScroll(viewRes.value.ELEMENT);
} else {
viewRes = this.getElementByType('tableview');
if (viewRes.status === codes.Success.code) {
return doScroll(viewRes.value.ELEMENT);
}
}
return {
status: codes.NoSuchElement.code,
value: null
};
}

, flickApp: function (startX, startY, endX, endY) {
var coords = this.getAbsCoords(startX, startY, endX, endY);

Expand Down
15 changes: 15 additions & 0 deletions lib/server/controller.js
Expand Up @@ -449,6 +449,20 @@ exports.mobileScrollTo = function (req, res) {
req.device.scrollTo(element, text, getResponseHandler(req, res));
};

exports.mobileScroll = function (req, res) {
req.body = _.defaults(req.body, {
direction: "down"
});
var direction = req.body.direction.toString().toLowerCase();

if (!_.contains(['up', 'left', 'right', 'down'], direction)) {
return respondError(req, res, status.codes.UnknownCommand.code,
new Error("Direction " + direction + " is not valid for scroll"));
}

req.device.scroll(direction, getResponseHandler(req, res));
};

exports.mobileShake = function (req, res) {
req.device.shake(getResponseHandler(req, res));
};
Expand Down Expand Up @@ -947,6 +961,7 @@ var mobileCmdMap = {
, 'flick': exports.mobileFlick
, 'swipe': exports.mobileSwipe
, 'scrollTo': exports.mobileScrollTo
, 'scroll': exports.mobileScroll
, 'shake': exports.mobileShake
, 'setLocation' : exports.mobileSetLocation
, 'hideKeyboard': exports.hideKeyboard
Expand Down
31 changes: 31 additions & 0 deletions test/functional/ios/uicatalog/gestures-specs.js
Expand Up @@ -423,6 +423,37 @@ describe('uicatalog - gestures -', function () {
});
});

describe('mobile: scroll', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });

it('should scroll down and up', function (done) {
var firstEl, location1, location2;
driver
.elementByTagName('tableCell')
.then(function (el) { firstEl = el; return el.getLocation(); })
.then(function (loc) { location1 = loc; })
.then(function () {
return driver.execute("mobile: scroll", [{direction: 'down'}]);
})
.then(function () { return firstEl.getLocation(); })
.then(function (loc2) {
location2 = loc2;
loc2.x.should.equal(location1.x);
loc2.y.should.not.equal(location1.y);
})
.then(function () {
return driver.execute("mobile: scroll", [{direction: 'up'}]);
})
.then(function () { return firstEl.getLocation(); })
.then(function (loc3) {
loc3.x.should.equal(location2.x);
loc3.y.should.not.equal(location2.y);
})
.nodeify(done);
});
});

describe('mobile shake', function () {
var driver;
setup(this, desired).then(function (d) { driver = d; });
Expand Down

10 comments on commit d2af796

@sekar73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using mobile:scroll. But, i'm getting an error that it hasn't been implemented yet. Could you please update me the current status on this feature?. Thanks

@jlipps
Copy link
Member Author

@jlipps jlipps commented on d2af796 Feb 19, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekar73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick response. Do we know when is the next release scheduled? Thanks.

@jlipps
Copy link
Member Author

@jlipps jlipps commented on d2af796 Feb 19, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekar73
Copy link

@sekar73 sekar73 commented on d2af796 Feb 27, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlipps
Copy link
Member Author

@jlipps jlipps commented on d2af796 Feb 27, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekar73
Copy link

@sekar73 sekar73 commented on d2af796 Feb 28, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlipps
Copy link
Member Author

@jlipps jlipps commented on d2af796 Feb 28, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekar73
Copy link

@sekar73 sekar73 commented on d2af796 Feb 28, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sekar73
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jonathan,
can you share a sample code that does pull to fresh on ios native app?

Please sign in to comment.