login.spec.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. describe('Login Page', () => {
  2. it('should successfully log in with correct credentials', () => {
  3. // Visit the base URL
  4. cy.visit('/');
  5. // Wait for the page to load and ensure the elements are present
  6. cy.get('[data-testid="login-username-input"]').should('be.visible');
  7. cy.get('[data-testid="login-password-input"]').should('be.visible');
  8. cy.get('[data-testid="login-submit-button"]').should('be.visible');
  9. // Enter the username
  10. cy.get('[data-testid="login-username-input"]').type('admin');
  11. // Enter the password
  12. cy.get('[data-testid="login-password-input"]').type('123456');
  13. // Click the login button
  14. cy.get('[data-testid="login-submit-button"]').click();
  15. // Wait for the login process to complete
  16. cy.contains('登录成功').should('be.visible', { timeout: 10000 });
  17. });
  18. it('should show an error message for incorrect credentials', () => {
  19. // Visit the base URL
  20. cy.visit('/');
  21. // Wait for the page to load and ensure the elements are present
  22. cy.get('[data-testid="login-username-input"]').should('be.visible');
  23. cy.get('[data-testid="login-password-input"]').should('be.visible');
  24. cy.get('[data-testid="login-submit-button"]').should('be.visible');
  25. // Enter the incorrect username
  26. cy.get('[data-testid="login-username-input"]').type('wronguser');
  27. // Enter the incorrect password
  28. cy.get('[data-testid="login-password-input"]').type('wrongpassword');
  29. // Click the login button
  30. cy.get('[data-testid="login-submit-button"]').click();
  31. // Wait for the error message to be visible
  32. cy.contains('登录失败').should('be.visible', { timeout: 10000 });
  33. });
  34. });