123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /**
- * ExitModalPage - 退出选择弹框的 Page Object
- *
- * 用于封装退出选择 modal 的交互操作
- */
- class ExitModalPage {
- /**
- * 验证 modal 是否可见
- */
- shouldBeVisible() {
- cy.get('[data-testid="exit-modal"]', { timeout: 5000 })
- .should('be.visible');
- return this;
- }
- /**
- * 验证 modal 是否已关闭
- * 通过检查 Modal 内的按钮是否不存在或不可见来判断
- * 这比检查 Modal 容器更可靠,因为:
- * 1. Ant Design 的 Modal 容器可能在关闭后仍保留在 DOM 中
- * 2. 按钮作为 Modal 的子元素,在 Modal 关闭时会被移除或隐藏
- * 3. 使用"不存在或不可见"的组合断言,兼容两种关闭方式
- *
- * 注意:设置了 2 秒超时以等待 Modal 的关闭动画完成
- */
- shouldNotBeVisible() {
- cy.get('body').then($body => {
- const button = $body.find('[data-testid="exit-modal-logout-button"]');
- if (button.length === 0) {
- // 按钮不存在,Modal 已关闭
- expect(button.length).to.equal(0);
- } else {
- // 按钮存在,检查是否不可见
- cy.get('[data-testid="exit-modal-logout-button"]', { timeout: 2000 })
- .should('not.be.visible');
- }
- });
- return this;
- }
- /**
- * 点击"注销用户"按钮
- */
- clickLogout() {
- cy.get('[data-testid="exit-modal-logout-button"]').click();
- return this;
- }
- /**
- * 点击"关闭程序"按钮
- */
- clickClose() {
- cy.get('[data-testid="exit-modal-close-button"]').click();
- return this;
- }
- /**
- * 点击"关机"按钮
- */
- clickShutdown() {
- cy.get('[data-testid="exit-modal-shutdown-button"]').click();
- return this;
- }
- /**
- * 点击"取消"按钮
- */
- clickCancel() {
- cy.get('[data-testid="exit-modal-cancel-button"]').click();
- return this;
- }
- /**
- * 获取"注销用户"按钮
- */
- getLogoutButton() {
- return cy.get('[data-testid="exit-modal-logout-button"]');
- }
- /**
- * 获取"关闭程序"按钮
- */
- getCloseButton() {
- return cy.get('[data-testid="exit-modal-close-button"]');
- }
- /**
- * 获取"关机"按钮
- */
- getShutdownButton() {
- return cy.get('[data-testid="exit-modal-shutdown-button"]');
- }
- /**
- * 获取"取消"按钮
- */
- getCancelButton() {
- return cy.get('[data-testid="exit-modal-cancel-button"]');
- }
- }
- export default ExitModalPage;
|