All steps shown as pass before protractor cucumber execution

江枫思渺然 提交于 2019-12-08 12:59:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!