// import 'cypress'; import { fileIndex } from '../util'; class LoginPage { visit(options?: { onBeforeLoad?: (win: Window) => void }) { // if (options?.onBeforeLoad) { // cy.visit(`${fileIndex}#/pages/index/index`, { // onBeforeLoad: options.onBeforeLoad // }); // } else { // cy.visit(`${fileIndex}#/pages/index/index`); // } cy.visit(`${fileIndex}#/pages/index/index`, { onBeforeLoad(win) { win.addEventListener('beforeunload', () => console.trace('beforeunload')); win.addEventListener('unload', () => console.trace('unload')); // ===== 新增两行:钉时间戳 ===== // cy.stub(win.Date, 'now').returns(1712345678901); // ======================================== // 保持原透传逻辑 options?.onBeforeLoad?.(win); } }); } getUsernameInput() { return cy.get('[data-testid="login-username-input"]'); } getPasswordInput() { return cy.get('[data-testid="login-password-input"]'); } getSubmitButton() { return cy.get('[data-testid="login-submit-button"]'); } login(username: string, password: string) { this.getUsernameInput().type(username); this.getPasswordInput().type(password); this.getSubmitButton().click(); } // 获取用户名标签文本 getUsernameLabel() { return cy.get('label').contains(/用户名|Username/); } // 获取密码标签文本 getPasswordLabel() { return cy.get('label').contains(/密码|Password/); } // 获取登录按钮 getLoginButton() { return cy.get('[data-testid="login-submit-button"]'); } // 获取急诊按钮 getEmergencyButton() { return cy.contains('button', /急诊|Emergency/); } // 验证页面是否为指定语言 verifyLanguage(locale: 'zh' | 'en') { if (locale === 'zh') { this.getUsernameLabel().should('contain', '用户名'); this.getPasswordLabel().should('contain', '密码'); this.getLoginButton().should('contain', '登录'); this.getEmergencyButton().should('contain', '急诊'); } else { this.getUsernameLabel().should('contain', 'Username'); this.getPasswordLabel().should('contain', 'Password'); this.getLoginButton().should('contain', 'Login'); this.getEmergencyButton().should('contain', 'Emergency'); } } // 验证占位符文本 verifyPlaceholders(locale: 'zh' | 'en') { if (locale === 'zh') { this.getUsernameInput().should('have.attr', 'placeholder', '请输入用户名'); this.getPasswordInput().should('have.attr', 'placeholder', '请输入密码'); } else { this.getUsernameInput().should('have.attr', 'placeholder', 'Enter username'); this.getPasswordInput().should('have.attr', 'placeholder', 'Enter password'); } } } export default LoginPage;