最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Protractor, Jasmine, and stopping test on first fail - Stack Overflow

programmeradmin3浏览0评论

While trying to figure out how to make certain jasmine expect statements dependent on a previous expect statement I discovered that previous to Jasmine 2.3.0, there was not a way. (see Stop jasmine test after first expect fails) However, Jasmine 2.3.0 added an option stopSpecOnExpectationFailure that when set to true will stop a test on the first failure.

Excited by this prospect, I modified my conf.js to include the option:

/*
 * conf.js
 */
exports.config = {
    framework: 'jasmine',
    specs: ['search-spec.js'],
    useAllAngular2AppRoots: true,
    jasmineNodeOpts: {
        stopSpecOnExpectationFailure: true
    }
};

But this did not work for me.

In my test, I have:

/**
 * Test option from select element is selected
 */
function verifyOptionSelected(option) {
   var myEl = $('select[value="' + option + '"]';

   expect(myEl.isPresent()).toBe(true, 'Option, ' + option + ', is not a value in the dropdown list. (It might be the text.)');

   expect(myEl.isSelected()).toBe(true, 'Option, ' + option + ', is not selected as expected.');
}

In the code above, both expect statements will be attempted, but I don't need the second to be attempted if the first fails.

Are there any of you who have figured this out with jasmine?

(Yes, I know about jasmine-bail-fast and protractor-fail-fast. However, in my opinion, using the built-in feature is a better solution.)

While trying to figure out how to make certain jasmine expect statements dependent on a previous expect statement I discovered that previous to Jasmine 2.3.0, there was not a way. (see Stop jasmine test after first expect fails) However, Jasmine 2.3.0 added an option stopSpecOnExpectationFailure that when set to true will stop a test on the first failure.

Excited by this prospect, I modified my conf.js to include the option:

/*
 * conf.js
 */
exports.config = {
    framework: 'jasmine',
    specs: ['search-spec.js'],
    useAllAngular2AppRoots: true,
    jasmineNodeOpts: {
        stopSpecOnExpectationFailure: true
    }
};

But this did not work for me.

In my test, I have:

/**
 * Test option from select element is selected
 */
function verifyOptionSelected(option) {
   var myEl = $('select[value="' + option + '"]';

   expect(myEl.isPresent()).toBe(true, 'Option, ' + option + ', is not a value in the dropdown list. (It might be the text.)');

   expect(myEl.isSelected()).toBe(true, 'Option, ' + option + ', is not selected as expected.');
}

In the code above, both expect statements will be attempted, but I don't need the second to be attempted if the first fails.

Are there any of you who have figured this out with jasmine?

(Yes, I know about jasmine-bail-fast and protractor-fail-fast. However, in my opinion, using the built-in feature is a better solution.)

Share Improve this question edited May 23, 2017 at 10:31 CommunityBot 11 silver badge asked May 19, 2016 at 21:12 MachtynMachtyn 3,2808 gold badges44 silver badges69 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

From what I see in the protractor and jasmine-npm (the jasmine runner that protractor uses) source code, it is not as simple as adding the stopSpecOnExpectationFailure or stopOnFailure jasmine node option to the configuration. There has to be changes applied to protractor to support the new stopSpecOnExpectationFailure jasmine node option. Please create an issue/feature request in Protractor issue tracker.


I've also tried to call the throwOnExpectationFailure function, set the stopSpecOnExpectationFailure value throw jasmine.getEnv() in onPrepare() but none of that worked. Perhaps, I am missing something and there is a way to enable the setting.

Execute npm install protractor-fail-fast

Then in protractor.conf.js

const failFast = require('protractor-fail-fast');

...
exports.config = {
  plugins: [
    failFast.init(),
  ],
  afterLaunch: function () {
    failFast.clean(); // Removes the fail file once all test runners have pleted.
  },
}

发布评论

评论列表(0)

  1. 暂无评论