如何从黄瓜/先锋/硒的浏览器中获取变量?

时间:2014-12-15 11:22:46

标签: testing cucumber

我有这样的脚本:

this.When(/^I should be logged in$/, function(value){
    console.log('> ', this.driver.executeScript('return "test"'));
});

console.log的输出是

>  { then: [Function: then],
  cancel: [Function: cancel],
  isPending: [Function: isPending] }

而不是

"> test"

2 个答案:

答案 0 :(得分:0)

尝试:

this.When(/^I should be logged in$/, function(value){
 var result = this.driver.executeScript('return "test"');
    console.log('> ', result );
});

答案 1 :(得分:0)

这是解决方案

    var result = this.driver.executeScript('return "test"');
    result.then(function(value){
        console.log(value)
    })

因为我认为它使用异步来与驱动程序通信。