admin管理员组

文章数量:1331538

I'm trying to run Nightwatch script which will open a url, then it will getValue from an Input and will use that value in the next page.

Please see the following code:

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();
    }
};

the setValue('input[name="first_name"]', first_name) gets "undefined"

first_name parameter is being updated inside a callback function. I need that setValue function will use the updated value. Thanks in advance

I'm trying to run Nightwatch script which will open a url, then it will getValue from an Input and will use that value in the next page.

Please see the following code:

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();
    }
};

the setValue('input[name="first_name"]', first_name) gets "undefined"

first_name parameter is being updated inside a callback function. I need that setValue function will use the updated value. Thanks in advance

Share Improve this question edited Aug 9, 2017 at 15:36 Oron Bendavid asked Aug 8, 2017 at 13:55 Oron BendavidOron Bendavid 1,5333 gold badges19 silver badges34 bronze badges 2
  • It could be related to this issue github./nightwatchjs/nightwatch/issues/1132. Calling setValue after clearValue seems to cause issues. – Chris Traveis Commented Aug 8, 2017 at 19:15
  • Hi thanks, It's not the case, I've found a workaround. Will post a solution in few minutes – Oron Bendavid Commented Aug 9, 2017 at 7:42
Add a ment  | 

1 Answer 1

Reset to default 5

I've found a workaround:

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();
    }
};

The solution is to use the browser.setValue again inside a callback.

本文标签: javascriptNightwatchjs get value from input and use it in next stepStack Overflow