量角器,Jasmine和首次停止测试失败 [英] Protractor, Jasmine, and stopping test on first fail

查看:182
本文介绍了量角器,Jasmine和首次停止测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在试图弄清楚如何使某些茉莉花期望语句依赖于先前的期望声明时,我发现在Jasmine 2.3.0之前,没有办法。 (参见首次预期失败后停止茉莉花测试)但是,Jasmine 2.3 .0添加了一个选项 stopSpecOnExpectationFailure 当设置为true时,将在第一次失败时停止测试。

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.

兴奋这个前景,我修改了我的conf.js以包括选项:

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
    }
};

但这对我不起作用。

在我的测试中,我有:

/**
 * 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语句,但如果第一个,我不需要尝试第二个失败。

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?

(是的,我知道关于 jasmine-bail-fast 量角器 - 失败-f但是,在我看来,使用内置功能是一个更好的解决方案。)

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

推荐答案

来自我在量角器中看到的内容以及 jasmine-npm 量角器使用的jasmine运行器)源代码,它不像添加<$ c那么简单$ c> stopSpecOnExpectationFailure 或 stopOnFailure 配置的jasmine node选项。必须对量角器进行更改以支持新的 stopSpecOnExpectationFailure jasmine节点选项。请在 量角器问题跟踪器中创建问题/功能请求

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.

我还尝试调用 throwOnExpectationFailure 函数,在 onPrepare() stopSpecOnExpectationFailure 值抛出 jasmine.getEnv() $ c>但这些都没有效果。也许,我错过了一些东西,有一种方法可以启用设置。

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.

这篇关于量角器,Jasmine和首次停止测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆