前端自動化測試解決方案探析(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

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97