即使期望语句失败,我的 Cucumber 步骤也已通过。在期望语句完成之前似乎正在运行步骤。
如果期望失败,请告诉我如何指示黄瓜步骤失败。
[文件夹结构] 以下是我的 Feature 文件
#features/test.feature
Feature: Running Cucumber with Protractor
As a user of Protractor
I should be able to use Cucumber
In order to run my E2E tests
Scenario: Protractor and Cucumber Test
Given I go to "https://angularjs.org/"
When I add "Be Awesome" in the task field
And I click the add button
Then I should see my new task in the list
以下是步骤定义
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');