Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在场景执行之前替换场景中的字符串_Node.js_Selenium_Cucumber_Ui Automation_Webdriver Io - Fatal编程技术网

Node.js 在场景执行之前替换场景中的字符串

Node.js 在场景执行之前替换场景中的字符串,node.js,selenium,cucumber,ui-automation,webdriver-io,Node.js,Selenium,Cucumber,Ui Automation,Webdriver Io,假设我有以下场景: 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

假设我有以下场景:

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 |
简而言之,这将映射提供给每个步骤的每个参数,并(通过
uniquify
函数)替换参数中的某些预定义文本,如
$timestamp


但问题是这不是我应该做的正确流程,我不想替换提供给每个步骤的每个参数,而是将
示例
的分布式参数替换为步骤,使ids
1
3
相同,而id
a
c
完全相同。

这个问题的正确解决方案与您实际需要的相差甚远,这就是在自动测试的每次迭代后清除数据库,因此您不需要创建随机或唯一的数字/字符串来维护测试中的唯一值

但是,知道如何修改每个测试/特性/场景/步骤的输入还是很方便的

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;
        });
      }
    });
  }