Skip to content

Commit

Permalink
feat: Add scroll instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed May 14, 2018
1 parent 1dbf4cd commit db731f1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Expand Up @@ -188,6 +188,7 @@ module.exports = function (grunt) {
},
{
url: 'http://localhost:8881/test/pages/input.html',
scroll: 'input',
moveCursor: 'input',
click: 'input',
wait: function (browser) {
Expand Down
21 changes: 21 additions & 0 deletions INSTRUCTIONS.md
Expand Up @@ -5,6 +5,7 @@ One of the instructions has to be present in every command. These properties are
- [setViewport](#setviewport)
- [url](#url)
- [go](#go)
- [scroll](#scroll)
- [clearValue](#clearvalue)
- [setValue](#setvalue)
- [addValue](#addvalue)
Expand Down Expand Up @@ -76,6 +77,26 @@ Navigates backwards or forwards using the browser history, or refreshes the curr
}
```

## scroll
Type: `String` | `Object`

Scrolls the page, so that the element with the specified selector or mouse coordinates become visible. If an object is used for the specification, it should contain the following properties:

* `selector` - `String` - selector of the element to move the mose to.
* `offset` - `Object` - relative offset to the top left corner of the specified element expected as `left` and `top` numeric properties.

```js
{
url: 'https://google.com',
scroll: {
selector: '#lst-ib'
},
file: 'google'
}
```

The `offset` value can be specified instead of the `selector` and shares the format with the [`moveCursor`](#moveCursor) instruction.

## clearValue
Type: `String`

Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -254,6 +254,7 @@ One of the [instructions] has to be present in every command. These properties a
* [setViewport](INSTRUCTIONS.md#setviewport)
* [url](INSTRUCTIONS.md#url)
* [go](INSTRUCTIONS.md#go)
* [scroll](INSTRUCTIONS.md#scroll)
* [clearValue](INSTRUCTIONS.md#clearvalue)
* [setValue](INSTRUCTIONS.md#setvalue)
* [addValue](INSTRUCTIONS.md#addvalue)
Expand Down Expand Up @@ -508,7 +509,7 @@ your code using Grunt.
## Release History
* 2018-05-14 [v1.3.0] Allow saving snapshots to sub-directories, file numbering per-directory
* 2018-05-14 [v1.3.0] Allow saving snapshots to sub-directories, file numbering per-directory, add `scroll` instruction
* 2018-05-11 [v1.2.0] Introduce delay after every instruction to be able to visually follow the actions when debugging
* 2018-03-29 [v1.1.0] Allow specifying all initialization parameters supported by WebdriverIO
* 2018-03-28 [v1.0.2] Stop Selenium and Chromedriver processes on unexpected Grunt process abortion
Expand Down
2 changes: 1 addition & 1 deletion tasks/html-dom-snapshot.js
Expand Up @@ -15,7 +15,7 @@ const {basename, dirname, isAbsolute, join} = require('path')
const mkdirp = require('mkdirp')
const nodeCleanup = require('node-cleanup')
const instructions = [
'setViewport', 'url', 'go', 'clearValue', 'setValue', 'addValue',
'setViewport', 'url', 'go', 'scroll', 'clearValue', 'setValue', 'addValue',
'selectOptionByIndex', 'selectOptionByValue', 'moveCursor',
'click', 'keys', 'wait', 'hasAttribute', 'hasClass', 'hasValue',
'hasText', 'hasInnerHtml', 'hasOuterHtml',
Expand Down
22 changes: 22 additions & 0 deletions tasks/instructions/scroll.js
@@ -0,0 +1,22 @@
'use strict'

module.exports = {
detect: function (command) {
return !!command.scroll
},

perform: function (grunt, target, client, command) {
let scroll = command.scroll
if (typeof scroll === 'string') {
scroll = {selector: scroll}
}
const selector = scroll.selector
if (selector) {
grunt.verbose.writeln('Move cursor to "' + selector + '".')
return client.scroll(selector)
}
const offset = scroll.offset || {}
grunt.verbose.writeln('Move cursor to ' + JSON.stringify(offset) + '.')
return client.scroll(offset.left, offset.top)
}
}

0 comments on commit db731f1

Please sign in to comment.