var readline = require('readline');
var test
rl = readline.createInterface(process.stdin, process.stdout);
rl.question('What is your favorite food?', function(answer) {
console.log('Oh, so your favorite food is ' + answer);
test = answer
});
rl.close()
webdriverio
.remote(options)
.init()
.url('http://www.google.com')
console.log(test) //undefined, why?
所以我不明白为什么它向我显示“未定义”而不是我通过终端输入的字符串。那是为什么?
我的猜测是不同步,但如何让它同步?
答案 0 :(得分:0)
修改了代码:
var readlineSync = require('readline-sync');
var test
webdriverio
.remote(options)
.init()
.url('http://www.google.com').then(function() {
test = readlineSync.question('What is your favorite food?'); //Honeyberry
console.log(test) //Honeyberry
})