简体   繁体   English

在运行时使用jasmine进行量角器中的条件测试跳过

[英]Conditional test skip in protractor using jasmine on runtime

My scenario is that one spec.js file contains many test cases let say 10 test case in smoke.js file.Excel sheet contains test data like Excel sheet name: smoke 我的方案是,一个spec.js文件包含许多测试用例,比如说smoke.js文件中的10个测试用例.Excel表包含测试数据,如Excel表单名称:smoke

Testcase--Execute 测试用例 - 执行

Test1 -- Yes 测试1 - 是的

Test2 -- No 测试2 - 没有

I read data from Excel and based on "Execute" column value need to run test. 我从Excel读取数据并根据“执行”列值需要运行测试。 I need to run "Test1" from smoke.js only and skip "Test2" . 我只需要从smoke.js运行“Test1”并跳过“Test2”。

I read many posts unfortunately i didn't get solution for my problem. 不幸的是,我读了许多帖子,但我没有得到解决方案。

You could prevent tests from happening with conditionals. 您可以阻止条件发生测试。 There might be a better way to do this. 可能有更好的方法来做到这一点。 Below is an example of how to do this: 以下是如何执行此操作的示例:

var tests = {
  'spec1': {
    'test1': 'Y',
    'test2': 'N'
  }
};


var spec1 = tests.spec1;
describe('spec1', () => {
  if (spec1.test1 == 'Y') {

    it('test1', () => {
      console.log('test1 executed');
    });
  } else {
    console.log('test1 not executed');
  }

  if (spec1.test2 == 'Y') {
    it('test2', () => {
      console.log('test2 executed');
    });
  } else {
    console.log('test2 not executed');
  }
});

In the example below I'm using var tests but in the above scenario, you could generate a JavaScript file from your spreadsheet prior to running the Protractor tests then require that file in your spec. 在下面的示例中,我使用的是var tests但在上面的场景中,您可以在运行Protractor测试之前从电子表格生成JavaScript文件,然后在规范中要求该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM