LoginPage.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // import 'cypress';
  2. import { fileIndex } from '../util';
  3. class LoginPage {
  4. visit(options?: { onBeforeLoad?: (win: Window) => void }) {
  5. // if (options?.onBeforeLoad) {
  6. // cy.visit(`${fileIndex}#/pages/index/index`, {
  7. // onBeforeLoad: options.onBeforeLoad
  8. // });
  9. // } else {
  10. // cy.visit(`${fileIndex}#/pages/index/index`);
  11. // }
  12. cy.visit(`${fileIndex}#/pages/index/index`, {
  13. onBeforeLoad(win) {
  14. win.addEventListener('beforeunload', () => console.trace('beforeunload'));
  15. win.addEventListener('unload', () => console.trace('unload'));
  16. // ===== 新增两行:钉时间戳 =====
  17. // cy.stub(win.Date, 'now').returns(1712345678901);
  18. // ========================================
  19. // 保持原透传逻辑
  20. options?.onBeforeLoad?.(win);
  21. }
  22. });
  23. }
  24. getUsernameInput() {
  25. return cy.get('[data-testid="login-username-input"]');
  26. }
  27. getPasswordInput() {
  28. return cy.get('[data-testid="login-password-input"]');
  29. }
  30. getSubmitButton() {
  31. return cy.get('[data-testid="login-submit-button"]');
  32. }
  33. login(username: string, password: string) {
  34. this.getUsernameInput().type(username);
  35. this.getPasswordInput().type(password);
  36. this.getSubmitButton().click();
  37. }
  38. }
  39. export default LoginPage;