Skip to content

Commit 559ce7e

Browse files
committed
feat: Introduce an optional delay after every instruction
...to be able to visually follow the actions when debugging.
1 parent b114070 commit 559ce7e

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

Gruntfile.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ module.exports = function (grunt) {
130130
url: 'http://localhost:8881/test/pages/no-doctype.html',
131131
file: 'no-doctype'
132132
},
133+
{
134+
options: {
135+
instructionDelay: 1
136+
},
137+
wait: 1
138+
},
133139
{
134140
url: 'http://localhost:8881/test/pages/dynamic-multiple.html'
135141
},

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Default options support the most usual usage scenario:
7878
height: 768
7979
},
8080
selectorTimeout: 10000,
81+
instructionDelay: 0,
8182
doctype: '<!DOCTYPE html>',
8283
snapshots: 'snapshots',
8384
screenshots: null,
@@ -148,7 +149,13 @@ Resizes the web browser viewport to the specified `width` and `height` values (i
148149
Type: `Number`
149150
Default value: 10000
150151

151-
Maximum waiting time, until a DOM node with the selector specified by the `wait` property appears or disappears. Taking the snapshot fails, if this time is exceeded.
152+
Maximum waiting time (in milliseconds), until a DOM node with the selector specified by the `wait` property appears or disappears. Taking the snapshot fails, if this time is exceeded.
153+
154+
#### instructionDelay
155+
Type: `Number`
156+
Default value: 0
157+
158+
Waiting time after executing an instruction. If the test is not run in the headless browser, but debugged in the browser window, it is sometimes helpful to watch outcome of every operation. If introducing waiting instructions all over is too cumbersome, this configuration will add the delay (in milliseconds) after every instruction automatically.
152159

153160
#### doctype
154161
Type: `String`
@@ -499,6 +506,7 @@ your code using Grunt.
499506
500507
## Release History
501508
509+
* 2018-05-11 [v1.2.0] Introduce delay after every instruction to be able to visually follow the actions when debugging
502510
* 2018-03-29 [v1.1.0] Allow specifying all initialization parameters supported by WebdriverIO
503511
* 2018-03-28 [v1.0.2] Stop Selenium and Chromedriver processes on unexpected Grunt process abortion
504512
* 2018-03-28 [v1.0.1] Workaround for hanging chromedriver after finishing the task
@@ -540,6 +548,16 @@ Licensed under the MIT license.
540548
[grunt-reg-viz]: https://github.com/prantlf/grunt-reg-viz
541549
[grunt-selenium-standalone]: https://github.com/zs-zs/grunt-selenium-standalone
542550
[keyboard key identifiers]: https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions
551+
[v1.2.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v1.2.0
552+
[v1.1.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v1.1.0
553+
[v1.0.2]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v1.0.2
554+
[v1.0.1]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v1.0.1
555+
[v1.0.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v1.0.0
556+
[v0.8.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.8.0
557+
[v0.7.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.7.0
558+
[v0.6.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.6.0
559+
[v0.5.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.5.0
560+
[v0.4.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.4.0
543561
[v0.3.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.3.0
544562
[v0.2.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.2.0
545563
[v0.1.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v0.1.0

tasks/html-dom-snapshot.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = grunt => {
4747
height: 768
4848
},
4949
selectorTimeout: 10000,
50+
instructionDelay: 0,
5051
doctype: '<!DOCTYPE html>',
5152
snapshots: 'snapshots',
5253
fileNumbering: false,
@@ -191,6 +192,7 @@ module.exports = grunt => {
191192
detected: instruction.detect(command)
192193
}
193194
})
195+
const instructionDelay = commandOptions.instructionDelay
194196
let snapshots = commandOptions.dest
195197
let viewportSet
196198
if (snapshots) {
@@ -208,7 +210,7 @@ module.exports = grunt => {
208210
viewport.height !== lastViewport.height) && !lastViewport.explicit) {
209211
lastViewport.width = viewport.width
210212
lastViewport.height = viewport.height
211-
viewportSet = setViewportSize()
213+
viewportSet = performInstruction(setViewportSize())
212214
} else {
213215
viewportSet = Promise.resolve()
214216
}
@@ -219,25 +221,34 @@ module.exports = grunt => {
219221
previous.then(() => {
220222
const detected = instruction.detected
221223
if (detected) {
222-
return instruction.perform(grunt, target, client, command,
223-
commandOptions, detected)
224+
return performInstruction(instruction.perform(grunt, target,
225+
client, command, commandOptions, detected))
224226
}
225227
}), viewportSet)
226228
.then(() => {
227229
if (snapshots && screenshots) {
228230
++fileCount
229-
return Promise.all([makeSnapshot(), makeScreenshot()])
231+
return performInstruction(
232+
Promise.all([makeSnapshot(), makeScreenshot()]))
230233
}
231234
if (snapshots) {
232235
++fileCount
233-
return makeSnapshot()
236+
return performInstruction(makeSnapshot())
234237
}
235238
if (screenshots) {
236239
++fileCount
237-
return makeScreenshot()
240+
return performInstruction(makeScreenshot())
238241
}
239242
})
240243

244+
function performInstruction (promise) {
245+
if (instructionDelay) {
246+
return promise.then(() => new Promise(
247+
resolve => setTimeout(resolve, instructionDelay)))
248+
}
249+
return promise
250+
}
251+
241252
function makeSnapshot () {
242253
return client.getHTML('html')
243254
.then(saveContent)

0 commit comments

Comments
 (0)