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
但问题是这不是我应该做的正确流程,我不想替换提供给每个步骤的每个参数,而是将
示例的分布式参数替换为步骤,使ids1
到3
相同,而ida
到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;
});
}
});
}