Skip to content

Commit caecf52

Browse files
committed
fix: Prefer WebDrivers to Selenium
1 parent 6afed0e commit caecf52

File tree

6 files changed

+4870
-6141
lines changed

6 files changed

+4870
-6141
lines changed

.coveralls.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

Gruntfile.js

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ module.exports = function (grunt) {
3737
}
3838
},
3939

40-
coveralls: {
41-
tests: {
42-
src: 'coverage/lcov.info'
43-
}
44-
},
45-
4640
nodeunit: {
4741
tests: ['test/*.js']
4842
},
@@ -604,56 +598,23 @@ module.exports = function (grunt) {
604598
}
605599
},
606600

607-
'selenium_standalone': {
608-
options: {
609-
stopOnExit: true
610-
},
611-
server: {
612-
seleniumVersion: '3.141.59',
613-
seleniumDownloadURL: 'http://selenium-release.storage.googleapis.com',
614-
drivers: {
615-
chrome: {
616-
version: '81.0.4044.69',
617-
arch: process.arch,
618-
baseURL: 'https://chromedriver.storage.googleapis.com',
619-
binary: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
620-
}
621-
// https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
622-
// edge: {
623-
// version: '6.17134'
624-
// },
625-
// https://github.com/mozilla/geckodriver/releases
626-
// firefox: {
627-
// version: '0.25.0'
628-
// },
629-
// https://selenium-release.storage.googleapis.com/
630-
// ie: {
631-
// version: '3.150',
632-
// arch: 'ia32'
633-
// },
634-
// https://selenium-release.storage.googleapis.com/
635-
// safari: {
636-
// version: '2.48'
637-
// }
638-
}
639-
}
601+
chromedriver: {
602+
default: {}
640603
}
641604
})
642605

643-
grunt.loadNpmTasks('@prantlf/grunt-selenium-standalone')
606+
grunt.loadNpmTasks('grunt-chromedriver')
644607
grunt.loadNpmTasks('grunt-contrib-clean')
645608
grunt.loadNpmTasks('grunt-contrib-connect')
646609
grunt.loadNpmTasks('grunt-contrib-nodeunit')
647-
grunt.loadNpmTasks('grunt-coveralls')
648610
grunt.loadNpmTasks('grunt-istanbul')
649611
grunt.loadNpmTasks('grunt-standard')
650612
grunt.loadTasks(coverage ? 'coverage/tasks' : 'tasks')
651613

652614
const test = ['clean', 'standard',
653-
'selenium_standalone:server:install',
654-
'selenium_standalone:server:start',
615+
'chromedriver:default:start',
655616
'connect', 'html-dom-snapshot',
656-
'selenium_standalone:server:stop', 'nodeunit']
617+
'chromedriver:default:stop', 'nodeunit']
657618
const report = coverage ? ['storeCoverage', 'makeReport'] : []
658619
grunt.registerTask('default', test.concat(report))
659620
}

README.md

Lines changed: 68 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# grunt-html-dom-snapshot
22
[![NPM version](https://badge.fury.io/js/grunt-html-dom-snapshot.png)](http://badge.fury.io/js/grunt-html-dom-snapshot)
33
[![Build Status](https://travis-ci.org/prantlf/grunt-html-dom-snapshot.png)](https://travis-ci.org/prantlf/grunt-html-dom-snapshot)
4-
[![Coverage Status](https://coveralls.io/repos/github/prantlf/grunt-html-dom-snapshot/badge.svg?branch=master)](https://coveralls.io/github/prantlf/grunt-html-dom-snapshot?branch=master)
54
[![Dependency Status](https://david-dm.org/prantlf/grunt-html-dom-snapshot.svg)](https://david-dm.org/prantlf/grunt-html-dom-snapshot)
65
[![devDependency Status](https://david-dm.org/prantlf/grunt-html-dom-snapshot/dev-status.svg)](https://david-dm.org/prantlf/grunt-html-dom-snapshot#info=devDependencies)
76
[![devDependency Status](https://david-dm.org/prantlf/grunt-html-dom-snapshot/peer-status.svg)](https://david-dm.org/prantlf/grunt-html-dom-snapshot#info=peerDependencies)
87

98
[![NPM Downloads](https://nodei.co/npm/grunt-html-dom-snapshot.png?downloads=true&stars=true)](https://www.npmjs.com/package/grunt-html-dom-snapshot)
109

11-
This module provides a grunt multi-task for taking "snapshots" of the HTML markup on web pages - of their immediate DOM content - and saving them to HTML files. It can be used to obtain content of web pages, which are built dynamically by JavaScript, and check it for validity and accessibility. It uses [webdriverio] and [Selenium] to control the selected web browser.
10+
This module provides a grunt multi-task for taking "snapshots" of the HTML markup on web pages - of their immediate DOM content - and saving them to HTML files. It can be used to obtain content of web pages, which are built dynamically by JavaScript, and check it for validity and accessibility. It uses [webdriverio] to control the selected web browser.
1211

1312
![Sample page](https://raw.githubusercontent.com/prantlf/grunt-html-dom-snapshot/master/assets/sample-page.png) ![Right arrow](https://raw.githubusercontent.com/prantlf/grunt-html-dom-snapshot/master/assets/arrow-right.png) ![Sample snapshot](https://raw.githubusercontent.com/prantlf/grunt-html-dom-snapshot/master/assets/sample-snapshot.png)
1413

1514
In addition, recent versions can save "screenshots" of browser viewport at the same time to support visual testing by comparing the look of the page with the baseline picture. Actually, this task is quickly evolving to offer end-to-end test capabilities too.
1615

1716
See the [migration documentation] about compatibility of older versions with the latest v6.
1817

18+
Recent versions of this documentation show how to use WebDrivers directly fror controlling the web browser ([grunt-chromedriver], [grunt-geckodriver] and [grunt-safaridriver]). It needs neither Java not [Selenum] installed. See the [version 6.0.1] or older for examples how to use the full [Selenium].
19+
1920
Additional Grunt tasks, which are usually used to support test automation:
2021

2122
* [grunt-accessibility] - checks accessibility of HTML markup according to the [WCAG] standard
@@ -24,6 +25,9 @@ Additional Grunt tasks, which are usually used to support test automation:
2425
* [grunt-html] - validates HTML markup according to the [W3C HTML] standard
2526
* [grunt-html-html-report-converter] - converts JSON report of `grunt-html` to HTML
2627
* [grunt-reg-viz] - compares images and generates report with differences
28+
* [grunt-chromedriver] - runs a standalone chromedriver - no need for Selenium
29+
* [grunt-geckodriver] - runs a standalone geckodriver - no need for Selenium
30+
* [grunt-safaridriver] - runs a standalone safaridriver - no need for Selenium
2731
* [@prantlf/grunt-selenium-standalone] - runs a standalone Selenium server
2832

2933
# Table of Contents
@@ -113,46 +117,21 @@ Make sure, that you have the stable version of Chrome installed, if you leave th
113117
Type: `Object`
114118
Default value: see above
115119

116-
Chooses the web browser to take snapshots with, Selenium host and other parameters supported by WebdriverIO as input for the `webdriverio.remote` method. This object has to contain the property `capabilities` with `browserName` and optionally other properties depending on the web browser driver. The following browser names are the most usually used: `chrome`, `edge`, `firefox`, `ie`, `phantomjs`, `safari`. Depending on what browser you specify, you will need to load the corresponding Selenium driver. These are current versions of the drivers:
120+
Chooses the web browser to take snapshots with, and other parameters supported by WebdriverIO as input for the `webdriverio.remote` method. This object has to contain the property `capabilities` with `browserName` and optionally other properties depending on the web browser driver. The following browser names are the most usually used: `chrome`, `firefox`, `safari`. Depending on what browser you specify, you will need to load the corresponding WebDdriver. These are the tasks to load the drivers:
117121

118122
```js
119-
'selenium_standalone': {
120-
serverConfig: {
121-
seleniumVersion: '3.141.59', // 3.7.1 or older is needed for phantomjs
122-
seleniumDownloadURL: 'http://selenium-release.storage.googleapis.com',
123-
drivers: {
124-
chrome: {
125-
version: '81.0.4044.69',
126-
arch: process.arch,
127-
baseURL: 'https://chromedriver.storage.googleapis.com'
128-
},
129-
// https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
130-
edge: {
131-
version: '6.17134'
132-
},
133-
// https://github.com/mozilla/geckodriver/releases
134-
firefox: {
135-
version: '0.26.0'
136-
},
137-
// https://selenium-release.storage.googleapis.com/
138-
ie: {
139-
version: '3.150.0',
140-
arch: 'ia32'
141-
},
142-
// https://selenium-release.storage.googleapis.com/
143-
safari: {
144-
version: '2.53'
145-
},
146-
// https://bitbucket.org/ariya/phantomjs/downloads/
147-
phantomjs: {
148-
version: '2.1.1'
149-
}
150-
}
151-
}
152-
}
123+
chromedriver: {
124+
default: { port: 4445 }
125+
},
126+
geckodriver: {
127+
default: { port: 4446 }
128+
},
129+
safaridriver: {
130+
default: { port: 4447 }
131+
},
153132
```
154133

155-
Th other often used property is `logLevel`, set to "warn" by default. Valid values are "trace", "debug", "info", "warn", "error" and "silent".
134+
The other often used property is `logLevel`, set to "warn" by default. Valid values are "trace", "debug", "info", "warn", "error" and "silent".
156135

157136
#### viewport
158137
Type: `Object`
@@ -468,7 +447,7 @@ grunt.registerTask('default', ['html-dom-snapshot', ...]);
468447
469448
## Example
470449
471-
When [webdriverio] is called, it needs to connect to a [Selenium] server. The easiest way, how to get it running is using the [@prantlf/grunt-selenium-standalone] Grunt task, which downloads, starts and stop the server. If the usage scenario is to validate static files or a mocked web application, a local web server like [grunt-contrib-connect] is usually added. And additional checking tasks like [grunt-html] pr [grunt-accessibility]. The complete Grunt initialization could look like this:
450+
When [webdriverio] is called, it needs to connect to a WebDriver or to the [Selenium] server. The easiest way, how to get it running, is using [grunt-chromedriver], [grunt-geckodriver], [grunt-safaridriver], or [@prantlf/grunt-selenium-standalone] Grunt tasks, which download, start and stop the browser. If the usage scenario is to validate static files or a mocked web application, a local web server like [grunt-contrib-connect] is usually added. And additional checking tasks like [grunt-html] pr [grunt-accessibility]. The complete Grunt initialisation could look like this:
472451
473452
```js
474453
grunt.initConfig({
@@ -500,127 +479,121 @@ grunt.initConfig({
500479
}
501480
},
502481

503-
'selenium_standalone': { // Provides a local Selenium server.
504-
serverConfig: {
505-
seleniumVersion: '3.141.59',
506-
seleniumDownloadURL: 'https://selenium-release.storage.googleapis.com',
507-
drivers: {
508-
chrome: {
509-
version: '81.0.4044.69',
510-
arch: process.arch,
511-
baseURL: 'https://chromedriver.storage.googleapis.com'
512-
}
513-
}
514-
}
482+
chromedriver: { // Launches the Chrome executable
483+
default: {}
515484
}
516485
});
517486

518-
grunt.loadNpmTasks('@prantlf/grunt-selenium-standalone');
519487
grunt.loadNpmTasks('grunt-accessibility');
488+
grunt.loadNpmTasks('grunt-chromedriver');
520489
grunt.loadNpmTasks('grunt-contrib-clean');
521490
grunt.loadNpmTasks('grunt-contrib-connect');
522491
grunt.loadNpmTasks('grunt-html');
523492
grunt.loadNpmTasks('grunt-html-dom-snapshot');
524493

525494
grunt.registerTask('default', [
526-
'selenium_standalone:serverConfig:install',
527-
'selenium_standalone:serverConfig:start',
495+
'chromedriver:default:start',
528496
'connect', 'clean', 'html-dom-snapshot',
529-
'selenium_standalone:serverConfig:stop',
497+
'chromedriver:default:stop',
530498
'htmllint', 'accessibility']);
531499
```
532500
533501
The installation of the necessary Grunt tasks:
534502
535-
```bash
536-
npm install grunt-html-dom-snapshot @prantlf/grunt-selenium-standalone \
537-
grunt-contrib-clean grunt-contrib-connect \
538-
grunt-accessibility grunt-html --save-dev
503+
```sh
504+
npm install grunt-html-dom-snapshot grunt-chromedriver \
505+
grunt-contrib-clean grunt-contrib-connect \
506+
grunt-accessibility grunt-html --save-dev
539507
```
540508
541509
### Notes
542510
543-
You will need to **install [Java] 8 or newer** to get the Selenium server running via the [@prantlf/grunt-selenium-standalone] Grunt task.
544-
545-
**If you want to use the PhantomJS driver, you will need to install the `phantomjs-prebuilt` module**. For example:
546-
547-
```shell
548-
$ npm install phantomjs-prebuilt --save-dev
549-
```
511+
Chrome, Chromium and Firefox support a headless mode. It simplifies automated testing, because you need no graphic subsystem like X.Org installed.
550512
551-
The `phantomjs` binary will be accessible in `./node_modules/.bin`. If you do not start the Selenium server using `npm test` or other `npm run` command, you will havew to add this directory to your `PATH`, otherwise the PhantomJS driver will not find the executable. Additionally, **PhantomJS 2.1.1 works only with the Selenium driver version 3.7.1 or older**. For example:
513+
The default configuration of this task will choose Chrome in the headless mode:
552514
553515
```js
554-
'selenium_standalone': {
555-
serverConfig: {
556-
seleniumVersion: '3.7.1',
557-
seleniumDownloadURL: 'http://selenium-release.storage.googleapis.com',
558-
drivers: {
559-
phantomjs: {
560-
version: '2.1.1'
516+
'html-dom-snapshot': {
517+
options: {
518+
webdriver: {
519+
capabilities: {
520+
browserName: 'chrome',
521+
'goog:chromeOptions': { args: ['--headless'] }
561522
}
562523
}
563524
}
564525
},
526+
chromedriver: {
527+
default: {}
528+
}
529+
```
530+
531+
If you want to run Chrome in the windowed mode, override the `chromeOptions` object with yours, even an empty one, which is missing the `--headless` argument, for example:
532+
533+
```js
565534
'html-dom-snapshot': {
566535
options: {
567536
webdriver: {
568537
capabilities: {
569-
browserName: 'phantomjs'
538+
browserName: 'chrome',
539+
'goog:chromeOptions': {}
570540
}
571541
}
572542
}
543+
},
544+
chromedriver: {
545+
default: {}
573546
}
574547
```
575548
576-
If you want to test with a headless browser, you may want to **prefer Chrome to PhantomJS**. Chrome can run in the headless mode too and PhantomJS is not developed any more. If you do - and it is the default, **make sure that a stable version of Chrome has been installed** on your machine.
577-
578-
The default configuration of this task will choose Chrome in the headless mode starting from the version 2.0.0 and newer:
549+
If you want to run Chrome in Travis CI, override the `goog:chromeOptions` object with yours and disable the sandbox with `--no-sandbox`:
579550
580551
```js
581552
'html-dom-snapshot': {
582553
options: {
583554
webdriver: {
584555
capabilities: {
585556
browserName: 'chrome',
586-
'goog:chromeOptions': {
587-
args: ['--headless']
588-
}
557+
'goog:chromeOptions': { args: ['--headless', '--no-sandbox'] }
589558
}
590559
}
591560
}
561+
},
562+
chromedriver: {
563+
default: {}
592564
}
593565
```
594566
595-
If you want to run Chrome in the windowed mode, override the `chromeOptions` object with yours, even an empty one, which is missing the `--headless` argument, for example:
567+
The following configuration will choose Firefox in the headless mode:
596568
597569
```js
598570
'html-dom-snapshot': {
599571
options: {
600572
webdriver: {
601573
capabilities: {
602-
browserName: 'chrome',
603-
'goog:chromeOptions': {}
574+
browserName: 'firefox',
575+
'moz:firefoxOptions': { args: ['-headless'] }
604576
}
605577
}
606578
}
579+
},
580+
geckodriver: {
581+
default: {}
607582
}
608583
```
609584
610-
If you want to run Chrome in Travis CI, override the `goog:chromeOptions` object with yours and disable the sandbox with `--no-sandbox`. **Chrome sandbox appears not working in Docker containers used by Travis**, but Chrome enbales it by default there. For example:
585+
The following configuration will choose Safari in the windowed mode:
611586
612587
```js
613588
'html-dom-snapshot': {
614589
options: {
615590
webdriver: {
616-
capabilities: {
617-
browserName: 'chrome',
618-
'goog:chromeOptions': {
619-
args: ['--headless', '--no-sandbox']
620-
}
621-
}
591+
capabilities: { browserName: 'safari' }
622592
}
623593
}
594+
},
595+
safaridriver: {
596+
default: {}
624597
}
625598
```
626599
@@ -680,7 +653,11 @@ Licensed under the MIT license.
680653
[grunt-html-html-report-converter]: https://github.com/prantlf/grunt-html-html-report-converter
681654
[grunt-reg-viz]: https://github.com/prantlf/grunt-reg-viz
682655
[@prantlf/grunt-selenium-standalone]: https://github.com/prantlf/grunt-selenium-standalone
656+
[grunt-chromedriver]: https://github.com/prantlf/grunt-chromedriver
657+
[grunt-geckodriver]: https://github.com/prantlf/grunt-geckodriver
658+
[grunt-safaridriver]: https://github.com/prantlf/grunt-safaridriver
683659
[keyboard key identifiers]: https://w3c.github.io/webdriver/webdriver-spec.html#keyboard-actions
660+
[version 6.0.1]: https://github.com/prantlf/grunt-html-dom-snapshot/tree/v6.0.1#readme
684661
[v6.0.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v6.0.0
685662
[v5.1.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v5.1.0
686663
[v4.0.0]: https://github.com/prantlf/grunt-html-dom-snapshot/releases/tag/v4.0.0

0 commit comments

Comments
 (0)