【发布时间】: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 |
我尝试做的是动态设置timestamp 和uuid 字段为每个测试创建不同的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 1 到 3 相同,并且 ids a 到 c 相同。
【问题讨论】:
标签: node.js selenium cucumber ui-automation webdriver-io