login.cy.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // import { describe, it } from 'node:test';
  2. import { mockLoginFail, mockLoginSuccess } from '../support/mock/handlers/user';
  3. import { mockGetSoftwareInfoSuccess } from '../support/mock/handlers/system';
  4. import { mockI18nSuccess } from '../support/mock/handlers/i18n';
  5. import LoginPage from '../support/pageObjects/LoginPage';
  6. // import "cypress";
  7. describe('Login Page', () => {
  8. const loginPage = new LoginPage();
  9. beforeEach(() => {
  10. // Mock software_info API to prevent 404 errors
  11. mockGetSoftwareInfoSuccess();
  12. // Mock i18n translation file
  13. mockI18nSuccess('zh_CN');
  14. });
  15. it('should successfully log in with correct credentials', () => {
  16. mockLoginSuccess();
  17. loginPage.visit();
  18. loginPage.getUsernameInput().should('be.visible');
  19. loginPage.getPasswordInput().should('be.visible');
  20. loginPage.getSubmitButton().should('be.visible');
  21. loginPage.login('admin', '123456');
  22. cy.wait('@loginSuccess');
  23. cy.contains('登录成功').should('be.visible', { timeout: 10000 });
  24. });
  25. it('should show an error message for incorrect credentials', () => {
  26. mockLoginFail();
  27. loginPage.visit();
  28. loginPage.getUsernameInput().should('be.visible');
  29. loginPage.getPasswordInput().should('be.visible');
  30. loginPage.getSubmitButton().should('be.visible');
  31. loginPage.login('wronguser', 'wrongpassword');
  32. cy.wait('@loginFail');
  33. cy.contains('登录失败').should('be.visible', { timeout: 10000 });
  34. });
  35. });