Created
March 30, 2014 23:15
-
-
Save asciidisco/9881577 to your computer and use it in GitHub Desktop.
This code is not tested, but at least should give you an inspiration on how to solve your issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save this as a seperate file & execute it before the second file | |
// It will collect all the links and store them in a file | |
module.exports = { | |
'Collect all the links': function (test) { | |
test.open('http://google.com') | |
// load all the links | |
.execute(function () { | |
var links = document.getElementsByTagName('a'); | |
var data = []; | |
for (var i = 0; i <= links.length; i++) { | |
data.push({href: links[i].href}); | |
} | |
this.data('links', JSON.stringify(data)); | |
}) | |
// abuse `log.message` to save the file | |
.log.message(function () { | |
var data = test.data('links'); | |
var fs = require('fs'); | |
fs.writeFileSync('links.json', data); | |
return data; | |
}) | |
.done(); | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save this as a seperate file & execute it after the first file has been executed | |
// Basically like so: `dalek collect_links.js && dalek link_executor.js` | |
module.exports = { | |
'Check all the links': function (test) { | |
var fs = require('fs'); | |
var raw = fs.readFileSync('links.json'); | |
var links = JSON.parse(raw); | |
// generate url checking tests for all links | |
links.forEach(function (link) { | |
// first, open starting page | |
test.open('http://google.com'); | |
// click the link | |
test.click('a[href="' + link.href + '"]') | |
// check the result | |
test.assert.url.to.contain('url_shoudl_contain_this_part', 'Works for link ' + link.href); | |
}); | |
test.done(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment