I have a nightwatch test that looks like so where I am attempting to confirm that a click of the "password-to-text" functionality of my login page works:
'Test Password Visible': function (client) {
client
.url('http://127.0.0.1:8000/test')
.waitForElementVisible('body', 1000)
.assert.visible('#id_password')
.assert.visible('#eye_button')
.pause(1000)
client.assert.attributeEquals("#id_password", "type", "password");
client.execute(function () {
document.querySelector('#eye_button').click()
console.log('clicked')
}, []);
client.assert.attributeEquals("#id_password", "type", "text");
},
#eye_button
is a div
that contains a JS controlled <i>
element showing if the password field is type=text
or type=password
I am new to Nightwatch but looking at other posts this should have enabled the div to be clicked, note the .click()
method did not work due to the element not being interactive.
client.execute(function () {
document.querySelector('#eye_button').click()
console.log('clicked')
}, []);
However it does not, and I do not even get the console.log when the test runs, can someone help point me in the right direction?
The line that fails is here because (I assume) the div is not clicked and the JS that converts the password field is not called:
client.assert.attributeEquals("#id_password", "type", "text");