1

我试图运行Nightwatch脚本,它将打开一个URL,然后它将从输入中获取值并将在下一页中使用该值。Nightwatch.js从输入中获取值并在下一步中使用

请参见下面的代码:

var conf = require('../../nightwatch.conf.BASIC.js'); 

module.exports = { 
    'nightwatch flow': function (browser) { 
     var first_name; 
     browser 
      .url('http://example:3000') 
      .getValue('input[name="first_name"]', function(result){ 
       first_name = result.value; 
      }) 
      .setValue('input[name="amount"]', 101) 
      .click('input[name=continue]') 
      .clearValue('input[name="first_name"]') 
      .setValue('input[name="first_name"]', first_name) 
      .click('button[name=next]') 
      .end(); 
    } 
}; 

setValue('input[name="first_name"]', first_name) 变得 “不确定”

FIRST_NAME参数是一个回调函数内更新。 我需要setValue函数将使用更新的值。 在此先感谢

+0

它可能与此问题有关https://github.com/nightwatchjs/nightwatch/issues/1132。在'clearValue'后面调用'setValue'似乎会导致问题。 –

+0

嗨,谢谢,事实并非如此,我找到了解决方法。将在几分钟内发布解决方案 –

回答

2

我已经找到了解决办法:

var conf = require('../../nightwatch.conf.BASIC.js'); 

var first_name; 

module.exports = { 
    'nightwatch flow': function (browser) { 
     browser 
      .url('http://example:3000') 
      .getValue('input[name="first_name"]', function(result){ 
       first_name = result.value; 
      }) 
      .setValue('input[name="amount"]', 101) 
      .click('input[name=continue]') 
      .clearValue('input[name="first_name"]') 
      .setValue('input[name="first_name"]', "", function(){ 
       browser.setValue('input[name="first_name"]', first_name) 
      }) 
      .click('button[name=next]') 
      .end(); 
    } 
}; 

的解决方案是再次使用browser.setValue回调中。

相关问题