【发布时间】:2021-07-29 00:11:19
【问题描述】:
在我们的 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:
/* 这个泛型函数用来验证里面所有的table td value assertions */
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..
}
});
【问题讨论】:
标签: cypress bdd cypress-cucumber-preprocessor