如何创建条件测试?
大家好!我正在尝试在柏树中创建有条件的测试,但无法弄清楚如何做。如果DOM中有一个元素,我必须执行一个构造。如果不是,那么应该只有一个通行证。如何实施它?
it("something test", () => {
cy.get("body").then(($body) => {
if ($body.find('button[name="button-row-add"]')) {
cy.get('button[name="button-row-add"]').click();
cy.get('input[name="newValue"]').type("Cypress Test String");
cy.get('button[name="submit-dimension"]').click();
cy.wait(500);
}
});
cy.get(".table-cell").each(($el) => {
cy.wrap($el).dblclick();
cy.wrap("[class^=form-cell]").as("form").should("exist");
cy.wrap("@form").get('textarea[name="value"]').type("Cypress Sell Test");
cy.wrap("@form").get('button[aria-label="submit-button"]').click();
});
})
Good day everyone! I'm trying to create a conditional test in cypress but can't figure out how to do it. I have a construct that must be executed if there is an element in the DOM. If it is not, then there should be just a pass. How to implement it?
it("something test", () => {
cy.get("body").then(($body) => {
if ($body.find('button[name="button-row-add"]')) {
cy.get('button[name="button-row-add"]').click();
cy.get('input[name="newValue"]').type("Cypress Test String");
cy.get('button[name="submit-dimension"]').click();
cy.wait(500);
}
});
cy.get(".table-cell").each(($el) => {
cy.wrap($el).dblclick();
cy.wrap("[class^=form-cell]").as("form").should("exist");
cy.wrap("@form").get('textarea[name="value"]').type("Cypress Sell Test");
cy.wrap("@form").get('button[aria-label="submit-button"]').click();
});
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做这样的事情:
You can do something like this: