Currently, I am in the process of setting up a new Nightwatch project to automate a basic Google search page. The assertion for searchbox present on page is successful, but I am facing difficulties performing any mouse or keyboard actions on the elements (SearchBox
, or SearchButton
)
Please note: The version of Nightwatch being used is 1.0
.
Test case:
module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com') // Navigate to URL
.waitForElementVisible('body', 10000) // Wait for page to load
.pause(2000)
.assert.title('Google') // Confirm site title matches
.assert.visible('input[name=q]')
.setValue('input[name=q]', 'nightwatchjs') // Enter values
.click('button[name=btnG]') // Click on search box
.pause(1000)
.end()
},
};
I have also attempted the following approach:
var setValue = function(sel, value) {
$(sel).val(value).change();
};
module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com') // Navigate to URL
.waitForElementVisible('body', 10000) // Wait for page to load
.pause(2000)
.assert.title('Google') // Confirm site title matches
.assert.visible('input[name=q]')
.execute(setValue, ['input[name=q]', 'nightwatchjs'])
.click('button[name=btnG]') // Click on search box
.pause(1000)
.end()
},
};
Below is the output log:
[Google] Test Suite
Running: Demo test Google
- √ Element was visible after 133 milliseconds.
- √ Testing if the page title equals "Google" - 18 ms.
- √ Testing if element is visible - 61 ms.
Error log:
Error encountered while running .setElementValue() protocol action: unknown error: call function result missing 'value'
TimeoutError: An issue arose while executing the .setValue() command on : {"status":-1, "state":"", "value": {"message":"unknown error: call function result missing 'value'", "error":[" (Session info: chrome=77.0.3865.120)"," (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.17763 x86_64)"]},"errorStatus":13,"error":"unknown error: call function result missing 'value'","httpStatusCode":200} at process._tickCallback (internal/process/next_tick.js:68:7) NoSuchElementError: A problem occurred during the execution of the .click() command on : at process._tickCallback (internal/process/next_tick.js:68:7)