前端自动化测试解决方案探析(9)

发表于:2016-11-23来源:ouven作者:ouven点击数: 标签:前端
输出内容为: $ casperjs sample.jsFirst Page: CasperJS - a navigation scripting testing utility for PhantomJS and SlimerJS written in Java scriptSecond Page: PhantomJS | PhantomJS 页面内的操作

  输出内容为:

$ 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