我在 Cypress 中得到了 2 个步骤定义,用于检查输入字段是否为空(取决于我如何构建使用 RegEx 设置的句子)。
首先我的问题是,柏树说测试失败,因为输入字段为空,而事实并非如此。
我定义的步骤:
/** We check if the input field with the given name is empty */
Given(/^The input field "(.*)" is (not )?empty$/, (inputFieldName, negation) => {
if (negation === 'not ') {
CypressTools.getByName(inputFieldName).should('not.be.empty');
} else {
CypressTools.getByName(inputFieldName).should('be.empty');
}
});
/** We check if the input field with the given name is visible and empty */
Given(/^The input field "(.*)" is visible and empty$/, (inputFieldName) => {
CypressTools.getByName(inputFieldName).should('be.visible').should('be.empty');
});
Run Code Online (Sandbox Code Playgroud)
在我的特定测试中,cypress 应该检查填充了值的输入字段,并且步骤的定义如下: 输入字段“XYZ”不为空
我可以看到,if …