Day 16 of 100daysofcode : Testing Websites using Cypress
describe(‘Login Automation Test’, () => {
const baseUrl = ‘https://the-internet.herokuapp.com’;
beforeEach(() => {
// Visit the base URL before each test
cy.visit(${baseUrl}/login);
});
it(‘should login successfully with valid credentials’, () => {
cy.get(‘#username’).type(‘tomsmith’); // Enter valid username
cy.get(‘#password’).type(‘SuperSecretPassword!’); // Enter valid password
cy.get(‘button[type=“submit”]’).click(); // Click the Login button
// Assert successful login
cy.get('.flash.success').should('contain.text', 'You logged into a secure area!');
});
it(‘should show error for invalid credentials’, () => {
cy.get(‘#username’).type(‘invalidUser’); // Enter invalid username
cy.get(‘#password’).type(‘invalidPassword’); // Enter invalid password
cy.get(‘button[type=“submit”]’).click(); // Click the Login button
// Assert error message
cy.get('.flash.error').should('contain.text', 'Your username is invalid!');
});
});
lebanon-mug