【问题标题】:How can I write parameterized tests with open source testcafe?如何使用开源 testcafe 编写参数化测试?
【发布时间】:2018-06-07 08:02:03
【问题描述】:

我发现很多introductions to parameterized tests/ test cases 用于测试咖啡馆,但语法与我使用的完全不同。我猜它们是针对已停产的付费版本的。如何使用免费版本做同样的事情?我不是专门寻找用户角色,我想编写带有参数的测试。

【问题讨论】:

    标签: testing e2e-testing testcase testcafe parameterized-tests


    【解决方案1】:

    你想做这样的事情吗? 这对我很有效

    import { Selector } from 'testcafe';
    
    fixture `Your fixture`
    .page `http://some_url.com`
    
    const testCases = [ 
        { name: 'name1', param: 'param1' },
        { name: 'name2', param: 'param2' }
        ...
    ];
    
    for (const c of testCases) {
        test(`Test ${c.name}`, async t => {
            yourTestMethod(c.param)
        });
    }
    

    【讨论】:

      【解决方案2】:

      可以通过使用 JS 和 YAML 的组合来添加额外的扭曲

      import YamlTableReader, {fixtureData, TestData} from "./YamlTableReader";
      
          var table = fixtureData `
              | ID                  | N1      | N2      | Equals |
              | Should Be equal     | 1       | 1       | true  |
              | Shouldn't be equal  | 1       | 2       | false  |
              | Shouldn't be equal  | 1       | "hans"  | false  |
              | Should be equal     | hans    | "hans"  | true  |
          `;
      
          table.forEach(row => {
            test('Should be equal', t => {
                row["Equals"] == (row["N1"] === row["N2"]));
               }
          }); 
      

      可以在这里找到简单的来源https://github.com/deicongmbh/jasmine-param-tests

      【讨论】:

      • 问题是关于 testcafe 而不是 jasmine
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-15
      相关资源
      最近更新 更多