问题
While executing my scripts, Immediately all steps shows as pass in console after that my actual scripts getting executed. Even after returning promise in each step.
Feature File:
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
Step Definition:
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);
});
}
And the Output shows as:
回答1:
There are marked as green because you don't resolve the promise.You've choosen in your setup not to return a callback
but to return a promise. This means that each last line of code should return a promise.
If you transform your code into promises you will get this
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);
});
}
来源:https://stackoverflow.com/questions/44310020/all-steps-shown-as-pass-before-protractor-cucumber-execution