You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
16
15
17
16
See the [migration documentation] about compatibility of older versions with the latest v6.
18
17
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
+
19
20
Additional Grunt tasks, which are usually used to support test automation:
20
21
21
22
*[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:
24
25
*[grunt-html] - validates HTML markup according to the [W3C HTML] standard
25
26
*[grunt-html-html-report-converter] - converts JSON report of `grunt-html` to HTML
26
27
*[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
27
31
*[@prantlf/grunt-selenium-standalone] - runs a standalone Selenium server
28
32
29
33
# Table of Contents
@@ -113,46 +117,21 @@ Make sure, that you have the stable version of Chrome installed, if you leave th
113
117
Type: `Object`
114
118
Default value: see above
115
119
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:
117
121
118
122
```js
119
-
'selenium_standalone': {
120
-
serverConfig: {
121
-
seleniumVersion:'3.141.59', // 3.7.1 or older is needed for phantomjs
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:
472
451
473
452
```js
474
453
grunt.initConfig({
@@ -500,127 +479,121 @@ grunt.initConfig({
500
479
}
501
480
},
502
481
503
-
'selenium_standalone': { // Provides a local Selenium server.
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.
550
512
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:
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
565
534
'html-dom-snapshot': {
566
535
options: {
567
536
webdriver: {
568
537
capabilities: {
569
-
browserName:'phantomjs'
538
+
browserName:'chrome',
539
+
'goog:chromeOptions': {}
570
540
}
571
541
}
572
542
}
543
+
},
544
+
chromedriver: {
545
+
default: {}
573
546
}
574
547
```
575
548
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`:
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:
596
568
597
569
```js
598
570
'html-dom-snapshot': {
599
571
options: {
600
572
webdriver: {
601
573
capabilities: {
602
-
browserName:'chrome',
603
-
'goog:chromeOptions': {}
574
+
browserName:'firefox',
575
+
'moz:firefoxOptions': { args: ['-headless'] }
604
576
}
605
577
}
606
578
}
579
+
},
580
+
geckodriver: {
581
+
default: {}
607
582
}
608
583
```
609
584
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:
611
586
612
587
```js
613
588
'html-dom-snapshot': {
614
589
options: {
615
590
webdriver: {
616
-
capabilities: {
617
-
browserName:'chrome',
618
-
'goog:chromeOptions': {
619
-
args: ['--headless', '--no-sandbox']
620
-
}
621
-
}
591
+
capabilities: { browserName:'safari' }
622
592
}
623
593
}
594
+
},
595
+
safaridriver: {
596
+
default: {}
624
597
}
625
598
```
626
599
@@ -680,7 +653,11 @@ Licensed under the MIT license.
0 commit comments