Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #618

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 87 additions & 2 deletions cypress/e2e/signIn.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,96 @@
/// <reference types="cypress" />
/// <reference types='cypress' />

describe('Sign In page', () => {
const login = 'tomsmith';
const pass = 'SuperSecretPassword!';
const rightSite = 'https://the-internet.herokuapp.com/secure';
const mainSite = 'https://the-internet.herokuapp.com/login';

beforeEach(() => {
cy.visit(mainSite);
});

describe('Site contents', () => {
it('should contain "Login Page" in header', () => {
cy.get('h2').should('have.text', 'Login Page');
});

it('should contain instruction in subheader', () => {
cy.get('h4')
.invoke('text')
.should((text) => {
expect(text.length).to.be.greaterThan(50);
});
});

it('should have a "Login" button', () => {
cy.get('.radius')
.should('have.text', ' Login')
.and('exist')
.and('be.visible')
.and('have.attr', 'type', 'submit');
});
});

describe('Valid login', () => {
beforeEach(() => {
cy.get('#username').type(login);
cy.get('#password').type(pass);
});

it('should login with valid data', () => {
cy.get('form').find('button[type="submit"]').click();
});

it('should return code 200 for POST method', () => {
cy.request({
method: 'POST',
url: 'https://the-internet.herokuapp.com/authenticate',
body: { username: login, password: pass }
}).then((response) => {
expect(response.status).to.eq(200);
});
});

it('should redirect to the correct site', () => {
cy.get('form').find('button[type="submit"]').click();
cy.url().should('eq', rightSite);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URL assertion is incorrect. The cy.url().should('eq', rightSite); should use cy.url().should('eq', rightSite); instead of cy.url().should('eq', rightSite);. Make sure to use cy.url().should('eq', rightSite); to correctly compare the current URL with the expected URL.

});
});

describe('Invalid login', () => {
it('should display error message for invalid login', () => {
cy.get('#username').type('tommssmith');
cy.get('#password').type(pass);
cy.get('form').find('button[type="submit"]').click();

cy.get('#flash')
.should('be.visible')
.and('contain', 'Your username is invalid!');
});

it(`should display error message for valid login
but invalid password`, () => {
cy.get('#username').type(login);
cy.get('#password').type('randompassword');
cy.get('form').find('button[type="submit"]').click();

cy.get('#flash')
.should('be.visible')
.and('contain', 'Your password is invalid!');
});
});

it('', () => {
describe('User Logout', () => {
beforeEach(() => {
cy.get('#username').type(login);
cy.get('#password').type(pass);
cy.get('form').find('button[type="submit"]').click();
});

it('should properly log out user', () => {
cy.get('.button').click();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selector .button for the logout button might be too generic. Ensure that this selector uniquely identifies the logout button to avoid potential issues if there are multiple elements with the same class.

cy.url().should('eq', mainSite);
});
});
});