I am currently utilizing Nightwatch.js (Selenium/WebDriver) to conduct tests on my Node.js application.
My objective now is to verify the existence of a navigation bar and ensure that the items within the navbar are as anticipated.
This is my attempt at retrieving all navigation items, but I am unsure how to validate these elements. Furthermore, I feel that this process may be overly complex. Is this the appropriate approach when using Nightwatch.js?
module.exports = {
'navigation': function(browser) {
var navElements = []
function getNavElements(elements) {
elements.value.forEach(function(element) {
browser.elementIdText(element.ELEMENT, function(res) {
navElements.push(res.value)
})
})
}
browser
.url(browser.launchUrl)
.waitForElementVisible('#nav', 10000)
browser.expect.element('#nav').to.be.present
browser.elements('css selector', '#nav > .item', getNavElements)
browser.expect(navElements).to.equal(['First', 'Second', 'Third'])
browser.end()
}
}