即使期望声明失败,我的黄瓜步也越来越多了。在expect语句完成之前,似乎步骤正在运行。
如果期望失败,请告诉我如何指示黄瓜步骤失败。
[文件夹结构]以下是我的功能文件
#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');
答案 0 :(得分:0)
我终于设法解决了这个问题。
Chai-as-promise版本为6.0,其对等依赖性为Chai版本> = 2.1.2且< 4。 我正在使用chai版本> 4所以我降级到版本2.1.2并且一切顺利。