I have a nightwatch test where I am testing a list of urls for mobile app content RSS, CSS, and HTML 'feeds'. They are in arrays like:
var rssFeeds = [
'https://www.example.com/rss/feed1',
'https://www.example.com/rss/feed2',
]
In my test, I am using a for loop to iterate through each url in the array to test like:
var urlToTest = ''; //< -- this is always 'https://www.example.com/rss/feed2' in .element check below
// rss Feeds
for (var i = 0; i < rssFeeds.length; i++) {
urlToTest = rssFeeds[i].toString()
browser
.url('https://validator.w3.org/feed/')
.waitForElementVisible('body', 'W3C RSS Validator page loaded... https://validator.w3.org/feed/ \n')
.setValue('#url', urlToTest)
.click('a[class="submit"]')
.element('css selector', 'img[title="Valid RSS"]', function (result) {
if (result.value && result.value.ELEMENT) {
// Element is present, do the appropriate tests
console.log('valid RSS...')
browser.perform(function () {
browser.verify.ok(1 == 1, urlToTest + ' valid RSS...') //<-- HERE
})
} else {
// Element is not present.
console.log('invalid RSS...')
browser.verify.ok(1 != 1, urlToTest + ' invalid RSS...') //<-- AND HERE
}
})
}
In each .url()
call, it is properly entering feed1, feed2, etc sequentially, however, in the .element()
call it is always the last value in the array, so the reporting looks wrong. It always looks like:
✓ appContent
TC004-AppContent
✓ W3C RSS Validator page loaded... https://validator.w3.org/feed/
✓ Passed [ok]: https://www.example.com/rss/feed2 valid RSS...
✓ W3C RSS Validator page loaded... https://validator.w3.org/feed/
✓ Passed [ok]: https://www.example.com/rss/feed2 valid RSS..
So, since urlToTest
is always the last array value, the report isn't very helpful right now by not differentiating what url is good/bad.
I tried wrapping different parts of the code in perform()
call to try to get it to run exactly when it needs too to no avail.
I also saw posts on .execute()
but I am just not getting it...
Any ideas are greatly appreciated.