【问题标题】:Replace strings in scenario before scenario execution在场景执行之前替换场景中的字符串
【发布时间】:2019-10-09 13:36:01
【问题描述】:

假设我有以下场景:

Scenario Outline: <testCase> <expectedResult>
  Given I open the site "#"
  When I add the following data to shipment
    | field_name | field_value   |
    | id_1       | <timestamp>   |    # 1570689270595
    | id_2       | <timestamp>   |    # 1570689270595
    | id_3       | <timestamp>   |    # 1570689270595
    | id_a       | <timestamp_2> |    # 1570689272523
    | id_b       | <timestamp_2> |    # 1570689272523
    | id_c       | <timestamp_2> |    # 1570689272523


  Examples:
    | testCase          | expectedResult | timestamp     | timestamp_2   |
    | CORRECT USER INFO | PASSES         | id_$timestamp | id_$timestamp |

我尝试做的是动态设置timestampuuid 字段为每个测试创建不同的ID,因为它必须是唯一的。我通过设置beforeScenario 钩子并在执行之前操纵场景来做到这一点,这是钩子的代码:

beforeScenario: function (uri, feature, scenario) {
    scenario.steps.forEach((step) => {
      if (step.arguments) {
        step.arguments.map((argument) => {
          if (typeof argument === 'string' || argument instanceof String)
            return uniquify(argument);
          if (argument.rows) {
            argument.rows = argument.rows.map((row) => {
              row.cells = row.cells.map((cell) => {
                cell.value = uniquify(cell.value);
                return cell;
              });
              return row;
            });
          }
          return argument;
        });
      }
    });
  }

简而言之,这会映射提供给每个步骤的每个参数,并替换(通过uniquify 函数)参数中的某些预定义文本,例如$timestamp

但问题是这不是我应该做的正确流程,我不想替换提供给每个步骤的每个参数,而是将Example 的分布式参数替换为步骤使 ids 13 相同,并且 ids ac 相同。

【问题讨论】:

    标签: node.js selenium cucumber ui-automation webdriver-io


    【解决方案1】:

    这个问题的正确解决方案与您可能真正想要的相差甚远,即在每次迭代后清除您的数据库以进行自动化测试,这样您就不需要按顺序创建随机或唯一的数字/字符串在您的测试中保持独特的价值。

    但是,知道如何修改每个测试/功能/场景/步骤的输入会很方便。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多