繁体   English   中英

Nightwatch 中的 setValue 方法不起作用

[英]setValue method in Nightwatch is not working

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

注意:我正在运行 Nightwatch 版本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()
       },
};

这是 output 日志:

[谷歌] 测试套件

运行:演示测试谷歌

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

错误日志:

运行时出错。setElementValue() 协议操作:未知错误:调用 function 结果缺少“值”

TimeoutError: 运行时发生错误。setValue() 命令 on: {"status":-1, "state":"", "value": {"message":"unknown error: call function result missing 'value'" , "error":[" (会话信息: chrome=77.0.3865.120)"," (驱动程序信息: 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: 运行时出错。点击()命令:在 process._tickCallback (internal/process/next_tick.js:68:7)

相同的代码在 Firefox 浏览器上工作。 我认为我使用的 ChromeBrowser 和 chromeDriver 存在一些问题。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM