在执行我的脚本时,所有步骤在我的实际脚本执行后立即显示为在控制台中传递。即使在每一步都退回承诺之后。
功能文件:
Feature: Running Cucumber with Protractor
Scenario: To verify the Search result
Given I am on home page
When I enter search value
Then I verify the search page
步骤定义:
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var expect = chai.expect;
chai.use(chaiAsPromised);
module.exports = function() {
this.Given(/^I am on home page$/, function () {
browser.get(browser.baseUrl);
return browser.driver.getTitle().then(function(pageTitle) {
expect(pageTitle).equal('Online Shopping Site for Mobiles, Fashion, Books, Electronics, Home Appliances and More');
});
});
this.When(/^I enter search value$/, function () {
return element(by.name('q')).sendKeys('iPhone 4s');
});
this.Then(/^I verify the search page$/, function () {
browser.sleep(1000);
return expect(element(by.className('KG9X1FUs7BSJ3tl0huXbH')).isPresent()).to.eventually.equal(true);
});
}
答案 0 :(得分:1)
标记为绿色,因为您无法解决承诺。您在设置中选择不返回callback
而是返回承诺。这意味着每个最后一行代码都应该返回一个promise。
如果您将代码转换为承诺,您将获得此
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var expect = chai.expect;
chai.use(chaiAsPromised);
module.exports = function() {
this.Given(/^I am on home page$/, function() {
browser.get(browser.baseUrl);
return expect(browser.driver.getTitle())
.to.eventually.equal('Online Shopping Site for Mobiles, Fashion, Books, Electronics, Home Appliances and More');
});
this.When(/^I enter search value$/, function() {
return element(by.name('q')).sendKeys('iPhone 4s');
});
this.Then(/^I verify the search page$/, function() {
browser.sleep(1000);
return expect(element(by.className('KG9X1FUs7BSJ3tl0huXbH')).isPresent()).to.eventually.equal(true);
});
}