| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- // 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');
- }
- }
- // 版本更新弹窗相关方法
- getVersionUpdateModal() {
- return cy.get('[data-testid="version-update-modal"]');
- }
- getUpdateNowButton() {
- return cy.get('[data-testid="update-now-btn"]');
- }
- getRemindLaterButton() {
- return cy.get('[data-testid="remind-later-btn"]');
- }
- getSkipVersionButton() {
- return cy.get('[data-testid="skip-version-btn"]');
- }
- // 下载进度弹窗相关方法
- getDownloadProgressModal() {
- return cy.get('[data-testid="download-progress-modal"]');
- }
- getDownloadProgressBar() {
- return cy.get('[data-testid="download-progress-bar"]');
- }
- getDownloadCancelButton() {
- return cy.get('[data-testid="download-cancel-btn"]');
- }
- }
- export default LoginPage;
|