官方说法A high-level browser automation library
,翻译过来就是高级浏览器自动化库html
经常使用于UI测试和爬网前端
功能测试必须在真正浏览器作,如今有四种方法。node
1.nightmare依赖于electron。安装electron(http://www.cnblogs.com/tanyongli/p/7504603.html)git
2.安装完后electron后安装Nightmaregithub
新建一个文件夹nightmare,在命令行里打开这个目录,执行 $ npm install nightmare
npm
出现warn:在其余文章中看到说能够先不用管浏览器
在nightmare文件夹里面出现node_modules文件夹less
在nightmare文件夹里新建example.js文件dom
example.jselectron
1 var Nightmare = require('nightmare'); 2 var nightmare = Nightmare({ show: true }) 3 4 nightmare 5 .goto('http://yahoo.com') 6 .type('form[action*="/search"] [name=p]', 'github nightmare') 7 .click('form[action*="/search"] [type=submit]') 8 .wait('#main') 9 .evaluate(function () { 10 return document.querySelector('#main .searchCenterMiddle li a').href 11 }) 12 .end() 13 .then(function (result) { 14 console.log(result) 15 }) 16 .catch(function (error) { 17 console.error('Search failed:', error); 18 });
而后在命令行里执行 $ node example.js
来执行example.js 这个文件,会出现效果图
参考网址:https://github.com/ruanyf/jstraining/blob/master/docs/engineering.md