写一个custom command进行夜间值类测试。
为什么我无法在以下代码片段中设置newValidFromText
的值?
exports.command = function () {
var newValidFromText; //Want to set value to this variable
var browser= this;
browser
.useCss()
.perform(function() {
//Setting the value to the variable 'newValidFromText'
newValidFromText = "June 1, 2017 "
//Testing the value set - console prints "June 1, 2017"
console.log( "newValidFromText now is: "+ newValidFromText );
})
.waitForElementVisible('input[id*="SubscriptionStart"]')
//Test for correct value - getting validFromText = undefined
.verify.valueContains('input[id*="SubscriptionStart"]', validFromText)
return browser.useCss();
};
最佳答案
因为您要求变量超出可见区域
exports.command = function () {
var newValidFromText; //Want to set value to this variable
var browser= this;
browser
.useCss()
.perform(function() {
//Setting the value to the variable 'newValidFromText'
newValidFromText = "June 1, 2017 "
//Testing the value set - console prints "June 1, 2017"
console.log( "newValidFromText now is: "+ newValidFromText );
this.waitForElementVisible('input[id*="SubscriptionStart"]')
.verify.valueContains('input[id*="SubscriptionStart"]', validFromText);
})
};
关于javascript - 在 Nightwatch 自定义命令中赋值后,变量返回未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43766842/