???????????????????????
??????????鵥????????????????????????????Σ?????????????????????????????????????????????????????????????????????????????б???????CasperJS??Nighmare??Nightwatch??Dalekjs????????????????
????· casperJS
????casperJS????PhantomJS??SlimerJS(PhantomJS??SlimerJS????????web????????????????????)????????????????????????????????????????
????var casper = require('casper').create();
????casper.start('http://casperjs.org/');
????casper.then(function() {
????this.echo('First Page: ' + this.getTitle());
????});
????casper.thenOpen('http://phantomjs.org'?? function() {
????this.echo('Second Page: ' + this.getTitle());
????});
????casper.run();
??????????????
????$ 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();
});
????· Nightmare
??????????nightmare??????????????????????????????????????????á??????????chrome????daydreem????????????????????????????У???????????????????????
????yield Nightmare()
????.goto('http://yahoo.com')
????.type('input[title="Search"]'?? 'github nightmare')
????.click('.searchsubmit');
????Nightmare??????????????????????????????chai.js????????????á?
var Nightmare = require('nightmare');
var expect = require('chai').expect; // jshint ignore:line
describe('test yahoo search results'?? function() {
it('should find the nightmare github link first'?? function(done) {
var nightmare = Nightmare()
nightmare
.goto('http://yahoo.com')
.type('form[action*="/search"] [name=p]'?? 'github nightmare')
.click('form[action*="/search"] [type=submit]')
.wait('#main')
.evaluate(function () {
return document.querySelector('#main .searchCenterMiddle li a').href
})
.end()
.then(function(link) {
expect(link).to.equal('https://github.com/segmentio/nightmare');
done();
})
});
});
????· Nightwatch
????Nightwatch????????node??д??????????????????Selenium server????????в???????????????????
this.demoTestGoogle = function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body'?? 1000)
.setValue('input[type=text]'?? 'nightwatch')
.waitForElementVisible('button[name=btnG]'?? 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main'?? 'The Night Watch')
.end();
};
????· Dalekjs
????DalekJS????????????????????????????????????????????????????????????????д?????????????????????е???????????????
module.exports = {
'Amazon does its thing': function (test) {
test
.open('http://www.amazon.com/')
.type('#twotabsearchtextbox'?? 'Blues Brothers VHS')
.click('.nav-submit-input')
.waitForElement('#result_0')
.assert.text('#result_0 .newaps a span').is('The Blues Brothers')
.done();
}
};
test.open('http://adomain.com')
.click('#aquestion')
.answer('Rose')
.assert.text('#aquestion').is('Rose'?? 'Awesome she was!')
.done();
????С????£???????????????????????????????????????????????????????ж?????ж????????????????????????????????????漰????????????????????????????????????????????????????????Ч???
???????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????С????????????????????
??????????????Щ???????????????????????????????????????????д?????????????????????????????????????????????У???????????????????????????????????????????????????????????????????????????????????????????ò?????????????????ò??????????????????????????????н??????????????????????£???д????????????????????????λ???????????????????????