【问题标题】:Protractor, Jasmine, and stopping test on first fail量角器、茉莉花和第一次失败时停止测试
【发布时间】:2016-09-16 23:22:40
【问题描述】:

在试图弄清楚如何使某些 jasmine 期望语句依赖于先前的期望语句时,我发现在 Jasmine 2.3.0 之前,没有办法。 (参见Stop jasmine test after first expect fails)但是,Jasmine 2.3.0 添加了一个选项stopSpecOnExpectationFailure,当设置为 true 时,将在第一次失败时停止测试。

对这个前景感到兴奋,我修改了我的 conf.js 以包含该选项:

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

但这对我不起作用。

在我的测试中,我有:

/**
 * 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.');
}

在上面的代码中,将尝试两个 expect 语句,但如果第一个失败,我不需要尝试第二个。

你们中有人用茉莉花解决了这个问题吗?

(是的,我知道jasmine-bail-fastprotractor-fail-fast。但是,在我看来,使用内置功能是更好的解决方案。)

【问题讨论】:

    标签: javascript jasmine protractor jasmine-node


    【解决方案1】:

    从我在protractorjasmine-npmprotractor使用的jasmine runner)源代码中看到的,并不像在配置中添加stopSpecOnExpectationFailurestopOnFailure jasmine节点选项那么简单.必须对protractor 进行更改以支持新的stopSpecOnExpectationFailure jasmine 节点选项。请在Protractor issue tracker 中创建问题/功能请求。


    我也尝试调用 throwOnExpectationFailure 函数,设置 stopSpecOnExpectationFailure 值 throw jasmine.getEnv() in onPrepare() 但这些都不起作用。也许,我遗漏了一些东西,并且有一种方法可以启用该设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      相关资源
      最近更新 更多