守夜人中的 setValue 方法不起作用



我正在尝试设置一个新的Nightwatch项目,目的是自动化一个简单的Google搜索页面。我对页面传递上存在的搜索框的断言,但我无法对元素(SearchboxSearchButton(执行任何鼠标/键盘操作

注意:我正在运行守夜人版本1.0

测试用例:

module.exports = {
before : function(browser) {
browser.globals.waitForConditionTimeout = 5000;
},
tags: ['google'],
'Demo test Google' : function (browser) {
browser 
.url('http://www.google.com') // Go to a url
.waitForElementVisible('body', 10000) // wait till page loads
.pause(2000)
.assert.title('Google') // Make sure Site title matches
.assert.visible('input[name=q]') 
.setValue('input[name=q]', 'nightwatchjs') // send values
.click('button[name=btnG]') // click on search box
.pause(1000)
.end()
},
};

我也尝试过这种方法:

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') // Go to a url
.waitForElementVisible('body', 10000) // wait till page loads
.pause(2000)
.assert.title('Google') // Make sure 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()
},
};

这是输出日志:

[谷歌] 测试套件

运行:演示测试谷歌

√元素在
  • 133 毫秒后可见。
  • √ 测试页面标题是否等于"Google" - 18 毫秒。
  • √ 测试元素是否可见 - 61 毫秒。

错误日志:

运行 .setElementValue(( 协议操作时出错:未知错误: 调用函数结果缺少"值">

超时错误:运行 .setValue(( 命令时出错 on : {"status":-1, "状态":", "值": {"消息":"未知错误:调用函数结果缺少'值'", "错误":[" (会话信息:chrome=77.0.3865.120(","(驱动程序信息:chromedriver = 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f(,platform=Windows NT 10.0.17763 x86_64("]},"错误状态":13,"错误":"未知错误:调用函数结果缺少"值","httpStatusCode":200} at process._tickCallback (internal/process/next_tick.js:68:7( NoSuchElementError:运行 .click(( 命令时出错 上: 在process._tickCallback(内部/进程/next_tick.js:68:7(

尝试先在输入上单击((,然后使用 setValue((,有时它会有所帮助