输出内容为:
$ casperjs sample.js First Page: CasperJS - a navigation scripting & testing utility for PhantomJS and SlimerJS written in Javascript Second Page: PhantomJS | PhantomJS |
页面内的操作结合casper的操作就可以这样来实现。
var casper = require('casper').create(); var links; function getLinks() { // Scrape the links from top-right nav of the website var links = document.querySelectorAll('ul.navigation li a'); return Array.prototype.map.call(links, function (e) { return e.getAttribute('href') }); } // Opens casperjs homepage casper.start('http://casperjs.org/'); casper.then(function () { links = this.evaluate(getLinks); }); casper.run(function () { for(var i in links) { console.log(links[i]); } casper.done(); }); |
原文转自:http://jixianqianduan.com/frontend-javascript/2016/11/22/front-end-auto-test.html