ui-automation - Cypress 类名查询返回错误的类名?
问题描述
我现在正在进行一项测试,检查单击某个 dom 元素后 dom 元素(前面板)的类名是否更改。我获取 Front Panel 的初始类名,然后单击必要的 dom 元素,然后再次查询 Front Panel 类名。虽然我可以在浏览器中清楚地看到不同的类名,但 Cypress 再次返回了 Front Panel 的初始类名。我在这里想念什么?
it('Changes Panel Background Color', () => {
cy.get('#Front_panel')
.invoke('attr', 'class')
.then(prevClassName => {
cy.get('#color_picker')
.children()
.first()
.children()
.first()
.children()
.first()
.children()
.first()
.children()
.first()
.click()
cy.get('#Front_panel')
.invoke('attr', 'class')
.then(newClassName => {
assert(prevClassName !== newClassName)
})
})
})
顺便说一句,我知道这可能不是赛普拉斯的最佳实践;)
解决方案
在我的情况下,我有一个测试可以很好地处理这种行为,用于检查模态显示是否正常。试试这个:
cy.log('has a info button');
cy.get('.home-header-info-button').click();
cy.get('.modal-header').should('contain', 'Health Details');
cy.get('.modal-body-health-info-name').should('contain', 'Tony');
cy.get('.modal-body-health-info-operator').should('contain', 'Doctor');
cy.get('.modal-body-info').should('be.visible');
cy.get('.modal-body-image').should('be.visible');
cy.get('.modal-footer').should('be.visible');
cy.get('.modal-header-close').click();
cy.get('.modal-header').should('not.exist');
导航到你的类名是一个更好的做法,因为对于其他时间阅读此测试的人来说,这将更具描述性和可读性。
推荐阅读
- c# - 输入数据时希望文本框清空
- r - 数据框之间的条件搜索、匹配、过滤和替换值
- vb.net - vb.net 托管内存和堆稳定但进程内存使用导致崩溃
- gcc - GCC libc 版本
- apache - Ant - 宏定义中 concat 目标中的字符串重复 - 为什么
- sql-server - 如何使用触发器更新 SQL Server 中的列
- c# - 返回线上的 Parasoft 违规 EXCEPT.NCSAE-3
- windows - 我可以将 Google Assistant 消息发送到我的 Windows 应用程序,但如何发回消息?
- asp.net - 无法将 IdentityServer4 添加到 ASP.NET Framework 4.7.2 API OWIN
- maven - 我在 Checkstyle 配置文件中的哪里放置模块元素?