我怎样才能用量角器创建条件的测试用例? [英] How can I create conditional test cases using Protractor?

查看:180
本文介绍了我怎样才能用量角器创建条件的测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有一些测试案例,我只希望在特定条件来执行。

Currently, I have some test cases that I only want to execute in certain conditions.

it ('user is able to log in', function() {
   if(siteAllowsLogin) {
       .....
   }

使用sitesNotAllowingLogin上述语法结果通过这项测试。我知道有标记测试为PENDING的解决方案,但我宁愿试验并没有显示,如果它是不适用的。

Using the above syntax results in sitesNotAllowingLogin to PASS this test. I know there is a solution to mark the test as PENDING, but I would rather the test did not show, if it was not applicable.

我也想保持测试用例内部的逻辑,如果可能的话。因此保持测试用例里面的if块。

I also want to keep the logic inside of the test case, if possible. So keeping the if block inside the test case.

。如果条件不满足,使其不会对结果显示PENDING或者传递如何跳过这个测试的任何建议。

Any suggestions on how to skip this test if the condition is not met so that it does not display on the results as PENDING or PASSED.

帮助将不胜AP preciated。

Help would be greatly appreciated.

推荐答案

您可以使用忽略前面函数燮preSS的测试,如果提供的predicate /状态是正确的:

You could use an ignore function in front to suppress the test if the provided predicate/state is true:

var ignore = function(exp){return{it:((typeof exp==='function')?exp():exp)?function(){}:it}};

describe('Suite 1', function() {

    it("test a", function() {
        expect(1).toEqual(1);
    });

    ignore(true).it("test b", function() {
        expect(1).toEqual(1);
    });

    ignore(skip).it("test c", function() {
        expect(1).toEqual(1);
    });

    function skip(){
      return true;
    }
});

这篇关于我怎样才能用量角器创建条件的测试用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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