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

时间:2019-10-09 13:36:01

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

说我有以下情况:

UpdateSourceTrigger=PropertyChanged

我尝试做的是动态设置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 | timestamp字段,以便为每个测试创建不同的ID,因为它必须唯一。我通过设置uuid挂钩并在场景执行之前对其进行了操作,这是挂钩的代码:

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相同的方式。

1 个答案:

答案 0 :(得分:0)

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

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