在我们的 BDD 自动化框架中,我们使用的是 Cypress Cucumber 预处理器库。我们计划为以下情况编写通用步骤定义。是否可以有一个步骤定义来处理下面提到的情况a to d
。现在我计划在两个步骤定义中处理这些案例,我们可以让它更通用,即在一个步骤定义中包含所有内容吗?
a) Then I "should not" see the value "Some_Value" in the "Reports_Logs" table
b) Then I "should" see the value "Some_Value" in the "Reports_Logs" table
c) Then I "should not" see the value in the "Users_Main" table ( in this case, I will read the value from the local storage )
d) Then I "should" see the value in the "Users_Main" table ( in this case, I will read the value from the local storage )
step defintion:
/* 这个通用函数用于验证里面所有的表 td 值断言 */
Then('I {string} see the value {string} in the {string} table', (checkCase, value, tableDatacy) => {
if(checkCase === "should"){
cy.get(`[data-cy=${tableDatacy}]`).find('tbody').find('tr').each(($tr) => {
cy.wrap($tr).find('td').each(($td) => {
const textName = Cypress.$($td).text();
switch (value) {
case textName.trim():
console.log("Condition got matched ...!!! " + textName.trim());
cy.wrap($tr).find('td').contains(textName.trim()).should('be.visible');
break;
}
});
});
} else if (checkCase === "should not") {
// rest of the check with this condition..
}
});