0
即使期望語句失敗,我的黃瓜步驟也會越過。看起來步驟在預期陳述完成之前運行。Cucmber.js步驟即使預期應該失敗也會越過
請讓我知道如果期望失敗,我該如何指導黃瓜步驟失敗。
[文件夾結構]下面是我的特性文件
下面是步驟定義
var chai = require('chai'),
expect = chai.expect,
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
var {defineSupportCode} = require('cucumber');
let scenarioTimeout = 200 * 1000;
defineSupportCode(({setDefaultTimeout}) => {
setDefaultTimeout(scenarioTimeout);
});
defineSupportCode(function({Given, When, Then}) {
Given(/^I go to "([^"]*)"$/, function(site) {
return browser.get(site);
});
When(/^I add "([^"]*)" in the task field$/, function(task) {
return element(by.model('todoList.todoText')).sendKeys(task);
});
When(/^I click the add button$/, function() {
var el = element(by.css('[value="add"]'));
return el.click();
});
Then(/^I should see my new task in the list$/, function() {
var todoList = element.all(by.repeater('todo in todoList.todos'));
return expect(todoList.get(2).getText()).to.eventually.equal('Not Awesome');
});
});
一切運作良好。如果我寫然後步驟如下:
解決方案1:
element.all(by.repeater('todo in todoList.todos')).then(function(items){
expect(items[2].getText()).to.eventually.equal('Not Awesome').and.notify(callback);
});
溶液2:
return element.all(by.repeater('todo in todoList.todos')).then(function(items){
return expect(items[2].getText()).to.eventually.equal('Not Awesome');
});
我真的想知道爲什麼,如果我寫了那麼一步以下方式不起作用:
Then(/^I should see my new task in the list$/, function() {
var todoList = element.all(by.repeater('todo in todoList.todos'));
return expect(todoList.get(2).getText()).to.eventually.equal('Not Awesome');