爲夜服測試編寫custom command。在夜服自定義命令中分配值後,變量返回undefined
爲什麼我不能在下面的代碼片段中設置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();
};
我同意這個解決方案。但我想知道這個內部。 – daredadevil
雖然您的答案是我將遵循的使用從回調中捕獲的數據的價值,但我更感興趣的是爲什麼會出現這種情況?對我來說,[我從文檔中找到的東西](http://stackoverflow.com/a/43786411/2605210)解釋了原因。 – daredadevil