Skip to content

Commit 9de12fc

Browse files
committed
chore: Upgrade WebdriverIO to the version 5 and adapt the task to stay compatible
chore: Upgrade other dependencies and require Node.js 8 or newer feat: Allow enabling of the "verbose" logging for this task only feat: Add a new instruction "elementSendKeys" for sending keys to a specific element BREAKING CHANGE: Upgraded WebdriverIO 5 and dropped support of Node.js 7 and older. Although the only broken instruction is `scroll`, which does not support the parameter `offset` any more, th eupgraded dependencies changed a lot and you wil lneed to check if your existing tests sill work.
1 parent c725559 commit 9de12fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+806
-392
lines changed

.ncurc.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

Gruntfile.js

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ module.exports = function (grunt) {
6565
options: {
6666
verbose: true,
6767
webdriver: {
68-
desiredCapabilities: {
68+
capabilities: {
6969
browserName: 'chrome',
70-
chromeOptions: {
70+
'goog:chromeOptions': {
7171
args: ['--headless', '--no-sandbox']
7272
}
7373
}
@@ -123,7 +123,8 @@ module.exports = function (grunt) {
123123
{
124124
url: 'http://localhost:8881/test/pages/dynamic-custom.html',
125125
wait: function (browser) {
126-
return browser.waitForExist('.dynamic', 1000)
126+
return browser.$('.dynamic')
127+
.then(element => element.waitForExist(1000))
127128
},
128129
file: 'dynamic-custom'
129130
},
@@ -196,7 +197,8 @@ module.exports = function (grunt) {
196197
moveCursor: 'input',
197198
click: 'input',
198199
wait: function (browser) {
199-
return browser.hasFocus('input')
200+
return browser.$('input')
201+
.then(element => element.isFocused())
200202
.then(function (value) {
201203
if (value !== true) {
202204
throw new Error('click failed')
@@ -205,15 +207,11 @@ module.exports = function (grunt) {
205207
}
206208
},
207209
{
208-
scroll: {
209-
offset: {
210-
top: 0,
211-
left: 0
212-
}
213-
},
210+
scroll: 'body',
214211
clickIfVisible: 'input',
215212
wait: function (browser) {
216-
return browser.hasFocus('input')
213+
return browser.$('input')
214+
.then(element => element.isFocused())
217215
.then(function (value) {
218216
if (value === false) {
219217
throw new Error('clickIfVisible on body failed')
@@ -227,7 +225,8 @@ module.exports = function (grunt) {
227225
value: 'Hi'
228226
},
229227
wait: function (browser) {
230-
return browser.getValue('input')
228+
return browser.$('input')
229+
.then(element => element.getValue())
231230
.then(function (value) {
232231
if (value !== 'Hi') {
233232
throw new Error('setValue failed')
@@ -241,7 +240,8 @@ module.exports = function (grunt) {
241240
value: ' there!'
242241
},
243242
wait: function (browser) {
244-
return browser.getValue('input')
243+
return browser.$('input')
244+
.then(element => element.getValue())
245245
.then(function (value) {
246246
if (value !== 'Hi there!') {
247247
throw new Error('addValue failed')
@@ -252,7 +252,8 @@ module.exports = function (grunt) {
252252
{
253253
clearValue: 'input',
254254
wait: function (browser) {
255-
return browser.getValue('input')
255+
return browser.$('input')
256+
.then(element => element.getValue())
256257
.then(function (value) {
257258
if (value !== '') {
258259
throw new Error('clearValue failed')
@@ -264,18 +265,36 @@ module.exports = function (grunt) {
264265
click: 'input',
265266
keys: 'test',
266267
wait: function (browser) {
267-
return browser.getValue('input')
268+
return browser.$('input')
269+
.then(element => element.getValue())
268270
.then(function (value) {
269271
if (value !== 'test') {
270272
throw new Error('sending text failed')
271273
}
272274
})
273275
}
274276
},
277+
{
278+
clearValue: 'input',
279+
elementSendKeys: {
280+
selector: 'input',
281+
text: 'Test'
282+
},
283+
wait: function (browser) {
284+
return browser.$('input')
285+
.then(element => element.getValue())
286+
.then(function (value) {
287+
if (value !== 'Test') {
288+
throw new Error('sending text to an element failed')
289+
}
290+
})
291+
}
292+
},
275293
{
276294
keys: ['Home', 'Delete'],
277295
wait: function (browser) {
278-
return browser.getValue('input')
296+
return browser.$('input')
297+
.then(element => element.getValue())
279298
.then(function (value) {
280299
if (value !== 'est') {
281300
throw new Error('sending key strokes failed', value)
@@ -322,7 +341,8 @@ module.exports = function (grunt) {
322341
coverage ? { wait: 1 } : {
323342
focus: 'body',
324343
wait: function (browser) {
325-
return browser.hasFocus('body')
344+
return browser.$('body')
345+
.then(element => element.isFocused())
326346
.then(function (value) {
327347
if (value !== false) {
328348
throw new Error('focus on body failed')
@@ -333,7 +353,8 @@ module.exports = function (grunt) {
333353
{
334354
clickIfVisible: 'input',
335355
wait: function (browser) {
336-
return browser.hasFocus('input')
356+
return browser.$('input')
357+
.then(element => element.isFocused())
337358
.then(function (value) {
338359
if (value !== false) {
339360
throw new Error('clickIfVisible on invisible input failed')
@@ -501,9 +522,9 @@ module.exports = function (grunt) {
501522
},
502523
'invalid-file': {
503524
options: {
504-
browserCapabilities: {
525+
capabilities: {
505526
browserName: 'chrome',
506-
chromeOptions: {
527+
'goog:chromeOptions': {
507528
args: ['--headless', '--no-sandbox']
508529
}
509530
},

INSTRUCTIONS.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ One of the instructions has to be present in every command. These properties are
1818
- [selectOptionByValue](#selectoptionbyvalue)
1919
- [moveCursor](#movecursor)
2020
- [click](#click)
21+
- [clickIfVisible](#clickIfVisible)
2122
- [keys](#keys)
23+
- [elementSendKeys](#elementSendKeys)
2224
- [wait](#wait)
2325
- [hasAttribute](#hasattribute)
2426
- [hasClass](#hasclass)
@@ -365,6 +367,19 @@ Moves the mouse cursor to an element with the specified selector. If an object i
365367
}
366368
```
367369

370+
## clickIfVisible
371+
Type: `String`
372+
373+
Triggers a click event on an element with the specified selector, if the elment is visible. Otherwise continues silently.
374+
375+
```js
376+
{
377+
url: 'https://google.com',
378+
clickIfVisible: 'input[name=btnK]',
379+
file: 'google'
380+
}
381+
```
382+
368383
## click
369384
Type: `String`
370385

@@ -392,6 +407,26 @@ Sends either a text (string) typed by keys, or single keystrokes (array) to the
392407
}
393408
```
394409

410+
## elementSendKeys
411+
Type: `Object`
412+
413+
Sends either a text (string), or single keystrokes (array) to an element in the browser. The object should contain the following properties:
414+
415+
* `selector` - `String` - selector of the element to send the keys or text to.
416+
* `text` - `String` - the text to send to the element.
417+
* `keys` - `Array<String>` - the keystrokes to send to the element.
418+
419+
```js
420+
{
421+
url: 'https://google.com',
422+
elementSendKeys: {
423+
selector: 'input[name=btnK]',
424+
text: 'test'
425+
},
426+
file: 'google'
427+
}
428+
```
429+
395430
## wait
396431
Type: `Number` | `String` | `Function` | `Array` (optional)
397432

@@ -433,7 +468,8 @@ If the selector is prefixed by the exclamation mark ("!"), the waiting waiting w
433468
{
434469
url: 'https://google.com',
435470
wait: function (browser) {
436-
return browser.waitForExist('#footer', 1000);
471+
return browser.$('#footer')
472+
.then(element => element.waitForExist(1000));
437473
},
438474
file: 'google'
439475
}

MIGRATION.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Migration from Earlier Versions
2+
3+
Increasing the major version means a breaking change in existing functionality, or at least deprecation of a feature, which has been replaced by an alternative. When you upgrade `grunt-html-dom-snapshot` to a higher major version, you might ned to update your configuration or even the task commands.
4+
5+
I recommend you upgrading `grunt-html-dom-snapshot` regularly. Functionality and security bugs are looked for and fixed in latest versions, not in old and thus little used ones.
6+
7+
# Upgrade Instructions
8+
9+
- [3 to 4](#3-to-4)
10+
- [2 to 3](#2-to-3)
11+
- [1 to 2](#1-to-2)
12+
- [0 to 1](#0-to-1)
13+
14+
## 3 to 4
15+
16+
Although you may not notice any breaking changes, **v4 upgraded to [WebdriverIO] 5 and dropped support of [Node.js] older than 8**. You should upgrade Node.js in your environment and check, that everything still works.
17+
18+
[WebdriverIO] overhauled its API, which meant adapting each instruction available in `grunt-html-dom-snapshot`. They all remained compatible, except for:
19+
20+
* [scroll](INSTRUCTIONS.md#scroll) does not support the `offset` parameter any more. Remove it. Scrolling will be performed to the center of the element.
21+
* [isVisible](INSTRUCTIONS.md#isvisible), [isNotVisible](INSTRUCTIONS.md#isnotvisible) and [clickIfVisible](INSTRUCTIONS.md#clickIfVisible) use the function [isElementDisplayed] which should work in the same way like the removed [isVisible], but you should still check if your visibility checks still work.
22+
23+
## 2 to 3
24+
25+
You will probably not notice any breaking changes in your scripts during this upgrade.
26+
27+
**Unrecognised instructions are forbidden in v3.** They hid typos in instruction that you wanted to execute. If you put foreign keys to the task commands, you will have to remove them and use comments instead, for example.
28+
29+
Old code:
30+
31+
```json
32+
{
33+
"doNotForget": "focus the other elements later",
34+
"click": "input",
35+
"file": "focused-input"
36+
}
37+
```
38+
39+
New code:
40+
41+
```json
42+
{
43+
// TODO: Focus the other elements later.
44+
"click": "input",
45+
"file": "focused-input"
46+
}
47+
```
48+
49+
See the [release notes for v3] for more information.
50+
51+
## 1 to 2
52+
53+
**v2 does not use PhantomJS by default any more.** The development has been stopped in favour of the headless mode introduced by Chrome and Firefox. You can still enable the webdriver for PhantomJS explicitly. However, it will be used less and less in the world and the quality of its support will deteriorate. Plan switching to the headless mode of Chrome and check, that your tests still work. If you did not use PhantomJS-specific API, you would only adapt the task configuration and should not notice any breaking changes in your scripts.
54+
55+
Old configuration:
56+
57+
```js
58+
'selenium_standalone': {
59+
serverConfig: {
60+
seleniumVersion: '3.7.1',
61+
seleniumDownloadURL: 'http://selenium-release.storage.googleapis.com',
62+
drivers: {
63+
phantomjs: {
64+
version: '2.1.1'
65+
}
66+
}
67+
}
68+
},
69+
'html-dom-snapshot': {
70+
options: {
71+
webdriver: {
72+
capabilities: {
73+
browserName: 'phantomjs'
74+
}
75+
}
76+
}
77+
}
78+
```
79+
80+
New configuration:
81+
82+
```js
83+
'selenium_standalone': {
84+
serverConfig: {
85+
seleniumVersion: '3.141.5',
86+
seleniumDownloadURL: 'http://selenium-release.storage.googleapis.com',
87+
drivers: {
88+
chrome: {
89+
version: '77.0.3865.40',
90+
arch: process.arch,
91+
baseURL: 'https://chromedriver.storage.googleapis.com'
92+
}
93+
}
94+
}
95+
},
96+
'html-dom-snapshot': {
97+
options: {
98+
webdriver: {
99+
capabilities: {
100+
browserName: 'chrome',
101+
'goog:chromeOptions': {
102+
args: ['--headless']
103+
}
104+
}
105+
}
106+
}
107+
}
108+
```
109+
110+
See the [release notes for v2] for more information.
111+
112+
## 0 to 1
113+
114+
**v1 runs only in Node.js 6 or newer.** Node.js 4 reeached its end-of-life and does not use PhantomJS by default any more. The development has been stopped in favour of the headless mode introduced by Chrome and Firefox. You can still enable the webdriver for PhantomJS explicitly. However, it will be used less and less in the world and the quality of its support will deteriorate. Plan switching to the headless mode of Chrome and check, that your tests still work. If you did not use PhantomJS-specific API, you would only adapt the task configuration and should not notice any breaking changes in your scripts.
115+
116+
See the [release notes for v1] for more information.
117+
118+
[WebdriverIO]: http://webdriver.io/
119+
[Node.js]: https://nodejs.org
120+
[isElementDisplayed]: https://webdriver.io/docs/api/webdriver.html#iselementdisplayed
121+
[isVisible]: http://v4.webdriver.io/api/state/isVisible.html
122+
[release notes for v4]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v4.0.0
123+
[release notes for v3]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v3.0.0
124+
[release notes for v2]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v2.0.0
125+
[release notes for v1]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v1.0.0

0 commit comments

Comments
 (0)