我对你的问题的理解是,你想要异步
Given, When, Then's
在里面
CucumberJS
表现为同步执行,因此,一旦
browser.get(url)
完成,然后执行下一步定义。如果这就是你的问题
对
我们可以做到-
你也需要
return
承诺或使用
done
步骤定义中的回调。否则,cucumber不知道异步操作何时完成。
我更喜欢
回来
当我使用.then函数和use对结果执行某些操作时
.done
当我不在的时候回调函数,你也不需要
callbacks
现在CucumberJS支持
promises
。因此,步骤文件应如下所示-
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
module.exports = function () {
this.Given(/^I launch the protractor demo page$/, function () {
return browser.get('http://juliemr.github.io/protractor-demo/');
});
});
this.When(/^I check the title of the page$/, function () {
return browser.getTitle().then(function(text){
console.log('title is - ' + text);
expect(text).to.equal('Super Calculator');
});
});