我已经有了一个方法,当它们有一些信息时,它会验证它,但是当没有信息时,它就崩溃了
Cypress.Commands.add('selectedFilterPlan', (filterId, idComponentList) => {
cy.get(filterId).should('be.visible');
cy.get(filterId).should('have.value', '');
cy.get(filterId)
.then((selects) => {
let select = selects[0];
cy.wrap(select).click();
if(cy.get(idComponentList).should("be.visible")){
cy.get(idComponentList)
.get("nz-option-item")
.then(function(item) {
cy.wrap(item[0]).click();
cy.wait(500);
cy.get("[data-cy=result-filter-list]").should("be.visible");
});
}
});
});_
it('select dropdown plan filters', () => {
cy.selectedFilterPlan('[data-cy=id-filter-1]', "#cdk-overlay-1");
cy.selectedFilterPlan('[data-cy=id-filter-2]', "#cdk-overlay-2");
cy.selectedFilterPlan('[data-cy=id-filter-3]', "#cdk-overlay-3");
cy.selectedFilterPlan('[data-cy=id-filter-4]', "#cdk-overlay-4");
cy.selectedFilterPlan('[data-cy=id-filter-5]', "#cdk-overlay-5");
});我想创建一个方法,当下一个字段为空时,验证并传递给下一个字段
发布于 2021-02-23 05:25:31
在您的自定义命令中,您在if语句中使用了cy.get(idComponentList).should("be.visible"),但是,()会产生相同的主题,在本例中是idComponentList。它不返回布尔值。在cypress文档中,明确指出cypress不适合进行条件测试。
如果您确实需要检查元素的存在,可以使用:Cypress.$('your_locator').length,它将返回DOM中存在的元素的数量。
if(Cypress.$(idComponentList).length !== 0)
或者,对于可见性,您可以使用Cypress.dom方法:
cy.get(idComponentList).then($el => {
Cypress.dom.isVisible($el) // true if visible
})我希望,这将是有用的。
https://stackoverflow.com/questions/66282354
复制相似问题