【问题标题】:How to run multiple feature files in sequence using Cucumber + protractor如何使用 Cucumber + protractor 依次运行多个特征文件
【发布时间】:2018-03-12 14:34:13
【问题描述】:

我想以所需的顺序或顺序运行功能文件,例如:

 tags:"`@ProtractorScenario` or @CucumberScenario" 

但是黄瓜场景首先被执行。有人可以指导我吗?

注意:Cucumber 是根据文件夹中特征文件的字母顺序执行场景

另外,如果特征文件超过 50 个,定义黄瓜特征文件排序的最佳方法是什么?

【问题讨论】:

    标签: protractor cucumber bdd ui-automation feature-file


    【解决方案1】:

    为了获得可靠的测试,您的测试应该是独立的,而不是依赖于它们运行的​​顺序。原因是您的测试不应该依赖于系统处于某种状态,因为这会导致片状测试。您的每个测试都应该设置预期的状态(和拆卸!),以便它们可以独立运行。

    【讨论】:

      【解决方案2】:

      以下是量角器如何执行黄瓜特征文件:

      1. 量角器找出specs中指定的所有特征文件,将文件绝对路径保存到数组中,我们称之为feature_list
      2. 量角器启动会话(启动浏览器实例)
      3. Protractor生成如下Cucumber CLI,执行CLI交出运行控制黄瓜:
        ./node_modules/bin/cucumber --require xxx --format xxx feature1,feature2,....featureN

        feature1,feature2,....featureN 由feature_list.join(',') 计算得出

      从上面我们可以了解到改变顺序的唯一机会 给量角器specs一个订单完成feature_list

      注意:feature_list 的每个成员都应该是绝对的/相对的 单个特征文件的路径。 folderwildcard 不建议出现在路径中。

      你可以从我的github获取解决方案代码:spec.filter.js,实现:

      1. 按 cucumberOpts.tags 过滤特征文件
      2. 按优先级排序上述步骤 1 的过滤结果

      spec.filter.js使用指南:

      // protractor conf file
      const specFilter = require('./spec.filter.js');
      
      var config = {
          seleniumAddress: 'xxxxx',
          capabilities:'xxxx',
      
          framework: 'custom',
          frameworkPath: require.resolve('protractor-cucumber-framework'),
          ignoreUncaughtExceptions: true,
      
          specs: [
              './aa/**/*.feature',
              './bb/**/*.feature'
          ],
      
          cucumberOpts: {
              require: [
                  'xxx'
              ],
              priorities: {
                   // feature has tag @SPGC-21542 or @SPGC-21944 or @SPGC-21946
                   // will has priority 1
                  '1': ['@SPGC-21542 or @SPGC-21944', '@SPGC-21946'], 
                   // feature has tag @SPGC-22055 will has priority 2, 
                   // feature has heighest priority will put ahead at 
                   // the `specs` list and get executed firstly.
                  '2': ['@SPGC-22055']
              }
              tags: ""
          }
      
          ....
      };
      
      exports.config = specFilter(config);
      

      【讨论】:

      • 如何通过量角器框架运行多个标签。我尝试了以下但失败 npx cross-env ENV=qa TAGS=@Smoke,@Regression yarn test
      猜你喜欢
      • 1970-01-01
      • 2019-09-28
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 2020-05-03
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多