Skip to content

Commit

Permalink
tests for Sign in developed
Browse files Browse the repository at this point in the history
  • Loading branch information
Kseniia Krytska committed Feb 20, 2025
1 parent f07058c commit 8787461
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
5 changes: 4 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const { defineConfig } = require('cypress');
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
}
},
baseUrl: 'https://the-internet.herokuapp.com',
viewportWidth: 1000,
viewportHeight: 650
}
});
31 changes: 30 additions & 1 deletion cypress/e2e/signIn.cy.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
/// <reference types="cypress" />
import SignInPage from '../pageObjects/signInObjects';
import SecurePage from '../pageObjects/secureObjects';
const signInPage = new SignInPage();

const securePage = new SecurePage();

const username = 'tomsmith';
const password = 'SuperSecretPassword!';

describe('Sign In page', () => {
beforeEach(() => {
cy.visit('/login');
});

it('should login with valid credentials', () => {
signInPage.typeInUsernameField(username);
signInPage.typeInPasswordField(password);
signInPage.clickLogin();
signInPage.assertNotification('You logged into a secure area!');
cy.assertUrl('/secure');
});

it('', () => {
it('should not login with invalid credentials', () => {
signInPage.typeInUsernameField('myusername');
signInPage.typeInPasswordField('jhHJu9=_');
signInPage.clickLogin();
signInPage.assertNotification('Your username is invalid!');
cy.assertUrl('/login');
});

it('should logout', () => {
signInPage.typeInUsernameField(username);
signInPage.typeInPasswordField(password);
signInPage.clickLogin();
securePage.logOutButton.click();
signInPage.assertNotification('You logged out of the secure area!');
cy.assertUrl('/login');
});
});
7 changes: 7 additions & 0 deletions cypress/pageObjects/secureObjects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

export default class SecurePage {
get logOutButton() {
return cy.get('[class="button secondary radius"]');
}
}
19 changes: 19 additions & 0 deletions cypress/pageObjects/signInObjects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// <reference types="cypress" />

export default class SignInPage {
typeInUsernameField(username) {
cy.get('#username').type(username);
}

typeInPasswordField(password) {
cy.get('#password').type(password);
}

clickLogin() {
cy.get('.radius').click();
}

assertNotification(text) {
cy.get('#flash').assertNotifText(text);
}
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,28 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

// Cypress.Commands.add('logInUser', (username, password) => {
// return cy.request('POST', 'https://the-internet.herokuapp.com/authenticate', {
// username,
// password
// }).then((response) => {
// console.log('Hooooraaaay!!!!');
// const returnedCookes = response.headers['set-cookie'];

// if(returnedCookes) {
// const authCookie = returnedCookes[0].split(';')[0].split('=')[1];
// // cy.setCookie('rack.session', authCookie, { path: '/', httpOnly: true })

// }
// });
// })

const parent = { prevSubject: 'element' };
Cypress.Commands.add('assertNotifText', parent, (subject, text) => {
cy.wrap(subject).should('contain.text', text);
});

Cypress.Commands.add('assertUrl', (url) => {
cy.url().should('equal', `${Cypress.config().baseUrl}${url}`);
});

0 comments on commit 8787461

Please sign in to comment.