2017-08-01 50 views

回答

1

是的,你可以得到幾個輸入值:

第一個選項是回調(不推薦):

var text, text2, text3; // ... 
browser.getValue('#inputField1', function (result) { 
    text = result.value; 
    browser.getValue('#inputField2', function (result) { 
    text2 = result.value; 
    browser.getValue('#inputField3', function (result) { 
     text3 = result.value; 
     browser.getValue('#inputField4' + text3, function (result) { 
     console.log(text, text2, text3) // your code 
     }); 
    }); 
    }); 
}); 

二,可以使用pe rform()從文件API(推薦):

var text, text2, text3; 
browser 
    .getValue('#input', function (result) { 
    text = result.value; 
    browser.getValue('#inputField2', function (result) { 
     text2 = result.value; 
    }); 
    }) 
    .perform(function() { 
    browser.getValue('#inputField3', function (result) { 
     console.log(text2, text 1) // they do exist here 
     text3 = result.value; 
    }); 
    }); 

這是文檔從nightwatch Perform

1

您可以使用gettext或getValue方法,例如:

this.demoTest = function (browser) { 
    browser.getText("#main ul li a.first", function(result) { 
    this.assert.equal(typeof result, "object"); 
    this.assert.equal(result.status, 0); 
    this.assert.equal(result.value, "nightwatchjs.org"); 
    }); 
}; 

this.demoTest = function (browser) { 
    browser.getValue("form.login input[type=text]", function(result) { 
    this.assert.equal(typeof result, "object"); 
    this.assert.equal(result.status, 0); 
    this.assert.equal(result.value, "enter username"); 
    }); 
}; 

有API文檔:getText API reference