Created
November 17, 2014 16:39
-
-
Save james-huston/130039c6c5927a83d9a0 to your computer and use it in GitHub Desktop.
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
module.exports = { | |
'link test': function (browser) { | |
var linkCount = 0; | |
var processed = 0; | |
var baseUrl = 'http://www.directvdeals.com'; | |
function processLinks(iteration) { | |
browser.execute(function (selector, counter) { | |
var current = document.getElementsByTagName(selector)[counter]; | |
current.click(); | |
return current.href; | |
}, ['a', iteration], function (result) { | |
console.log(result); | |
if (!result.value || !result.value.length) { | |
// this link appears to have returned an empty href so it may | |
// not have had one. that's ok, return back home and go to the | |
// next one. | |
console.log('skipping empty URL', iteration); | |
processed++; | |
browser | |
.url(baseUrl) | |
.waitForElementVisible('.h-phone', 4000, function () { | |
processLinks(processed); | |
}); | |
} | |
browser | |
// give the page a second to load. Not sure I like this or if it's | |
// enough time so this may need tweaked. | |
.pause(1000) | |
// make sure our current URL matches the one on the link we clicked | |
.assert.urlEquals(result.value) | |
// return back home | |
.url(baseUrl) | |
.waitForElementVisible('.h-phone', 4000) | |
.pause(500, function () { | |
// if (result.success !== 1) { | |
// throw new Error(result.value); | |
// } | |
console.log('processed a click'); | |
processed++; | |
console.log('processed', processed, 'links', linkCount); | |
if (processed === linkCount) { | |
// we have processed all links, go ahead and end. | |
console.log('ending'); | |
browser.end(); | |
} else { | |
// go to the next link. | |
processLinks(processed); | |
} | |
}); | |
}); | |
} | |
browser | |
.url(baseUrl) | |
.waitForElementVisible('.h-phone', 4000) | |
.execute(function (selector) { | |
return document.getElementsByTagName(selector); | |
}, ['a'], function (elements) { | |
console.log('elements found', elements.value.length); | |
linkCount = elements.value.length; | |
processLinks(processed); | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment