ExitModalPage.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * ExitModalPage - 退出选择弹框的 Page Object
  3. *
  4. * 用于封装退出选择 modal 的交互操作
  5. */
  6. class ExitModalPage {
  7. /**
  8. * 验证 modal 是否可见
  9. */
  10. shouldBeVisible() {
  11. cy.get('[data-testid="exit-modal"]', { timeout: 5000 })
  12. .should('be.visible');
  13. return this;
  14. }
  15. /**
  16. * 验证 modal 是否已关闭
  17. * 通过检查 Modal 内的按钮是否不存在或不可见来判断
  18. * 这比检查 Modal 容器更可靠,因为:
  19. * 1. Ant Design 的 Modal 容器可能在关闭后仍保留在 DOM 中
  20. * 2. 按钮作为 Modal 的子元素,在 Modal 关闭时会被移除或隐藏
  21. * 3. 使用"不存在或不可见"的组合断言,兼容两种关闭方式
  22. *
  23. * 注意:设置了 2 秒超时以等待 Modal 的关闭动画完成
  24. */
  25. shouldNotBeVisible() {
  26. cy.get('body').then($body => {
  27. const button = $body.find('[data-testid="exit-modal-logout-button"]');
  28. if (button.length === 0) {
  29. // 按钮不存在,Modal 已关闭
  30. expect(button.length).to.equal(0);
  31. } else {
  32. // 按钮存在,检查是否不可见
  33. cy.get('[data-testid="exit-modal-logout-button"]', { timeout: 2000 })
  34. .should('not.be.visible');
  35. }
  36. });
  37. return this;
  38. }
  39. /**
  40. * 点击"注销用户"按钮
  41. */
  42. clickLogout() {
  43. cy.get('[data-testid="exit-modal-logout-button"]').click();
  44. return this;
  45. }
  46. /**
  47. * 点击"关闭程序"按钮
  48. */
  49. clickClose() {
  50. cy.get('[data-testid="exit-modal-close-button"]').click();
  51. return this;
  52. }
  53. /**
  54. * 点击"关机"按钮
  55. */
  56. clickShutdown() {
  57. cy.get('[data-testid="exit-modal-shutdown-button"]').click();
  58. return this;
  59. }
  60. /**
  61. * 点击"取消"按钮
  62. */
  63. clickCancel() {
  64. cy.get('[data-testid="exit-modal-cancel-button"]').click();
  65. return this;
  66. }
  67. /**
  68. * 获取"注销用户"按钮
  69. */
  70. getLogoutButton() {
  71. return cy.get('[data-testid="exit-modal-logout-button"]');
  72. }
  73. /**
  74. * 获取"关闭程序"按钮
  75. */
  76. getCloseButton() {
  77. return cy.get('[data-testid="exit-modal-close-button"]');
  78. }
  79. /**
  80. * 获取"关机"按钮
  81. */
  82. getShutdownButton() {
  83. return cy.get('[data-testid="exit-modal-shutdown-button"]');
  84. }
  85. /**
  86. * 获取"取消"按钮
  87. */
  88. getCancelButton() {
  89. return cy.get('[data-testid="exit-modal-cancel-button"]');
  90. }
  91. }
  92. export default ExitModalPage;