dom-validate
A tool to check required/refused DOM nodes, can also output TAP or JUnit reports
![Build Status](https://travis-ci.org/zordius/dom-validate.svg?branch=master)
Usage
# Install
npm install dom-validate -g
# Check for Google page, there should be a .lsb element
node-validate -u 'https://google.com/' -r '.lsb' -v=2
# Check for Yahoo page, there should not be any empty link
node-validate -u 'https://us.yahoo.com/' -n 'a[href=""]' -v=2
# Yes, there should not be any broken images...check again
node-validate -u 'https://us.yahoo.com/' -n 'img[src=""]' -v=2
Command line options
- -u specify a url string to verify
- -r specify the css selector for the required element
- -n specify the css selector for the refused element
- -v show verbose message for the error cases
- -v=2 show verbose message for the success cases
- -v=3 show verbose message for the html of css selector selected elements
- -c [BATCH] specify a local yaml config file to do batch check
- -b [BATCH] specify base URL
- -t [BATCH] output result as TAP format
The exit code will be the number of failed cases.
BATCH check example
Try this command: node-validate -c sample.yaml -b https://tw.search.yahoo.com -v=2
The content of sample.yaml can be:
http://google.com:
require: .lsb
http://us.yahoo.com:
require:
- body > div
- form
/search?p=test:
require:
- body > div
- form button
refuse:
- 'a[href=""]'
Sample output:
# check for http://google.com
OK: required element ".lsb" found(2)
# check for http://us.yahoo.com
OK: required element "body > div" found(2)
OK: required element "form" found(1)
# check for https://tw.search.yahoo.com/search?p=test
OK: required element "body > div" found(1)
OK: required element "form button" found(2)
OK: refused element "a[href=""]" not found
Output test report
Try this to save TAP report file as result.tap:
node-validate -c sample.yaml -b https://tw.search.yahoo.com -t > result.tap
You may also get JUnit (xUnit) report file by:
npm install tap-xunit -g
node-validate -c sample.yaml -b https://tw.search.yahoo.com -t | tap-xunit > junit-result.xml
node module usage
var DV = require('dom-validate');
DV.validateHTML(htmlString, options);
DV.validateURL(urlString, options);
DV.validateByYaml(yamlFileName, options);
Options
var options = {
url: 'http://sample.com',
baseURL: 'https://test.com',
require: 'body',
refuse: ['a[href=""]', 'img[src=""]'],
exit: false,
verbose: false,
report: false,
callback: function (err, options) {
if (err) {
console.log('ERROR!' + err);
return;
} else {
connsole.log('OK!');
}
}
};