最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

在方案执行之前替换方案中的字符串

IT培训 admin 5浏览 0评论

在方案执行之前替换方案中的字符串

说我有以下情况:

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

但是问题是这不是我应该做的正确流程,我不想替换提供给每个步骤的每个参数,而是要以使ID Example1相同,且ID 3a相同。

回答如下:

此问题的正确解决方案与您实际想要的相去甚远,后者是在每次迭代后为自动测试清除数据库,因此您无需创建随机或唯一的数字/字符串即可。在测试中保持唯一的值。

在方案执行之前替换方案中的字符串

说我有以下情况:

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

但是问题是这不是我应该做的正确流程,我不想替换提供给每个步骤的每个参数,而是要以使ID Example1相同,且ID 3a相同。

回答如下:

此问题的正确解决方案与您实际想要的相去甚远,后者是在每次迭代后为自动测试清除数据库,因此您无需创建随机或唯一的数字/字符串即可。在测试中保持唯一的值。

发布评论

评论列表 (0)

  1. 暂无评论