Skip to content

Commit

Permalink
Automated authentication scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Hubale <ganeshhubale03@gmail.com>
  • Loading branch information
ganeshhubale committed Jan 8, 2025
1 parent 464a30a commit b1485a5
Show file tree
Hide file tree
Showing 17 changed files with 2,750 additions and 1,420 deletions.
20 changes: 20 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
e2e: {
chromeWebSecurity: false,
pageLoadTimeout: 60000,
baseUrl: 'https://www.saucedemo.com',
specPattern: 'cypress/e2e/**/*.cy.js',
supportFile: 'cypress/support/e2e.js',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
env: {
username: "standard_user",
password: "secret_sauce",
},
viewportWidth: 1280,
viewportHeight: 720,
});
10 changes: 0 additions & 10 deletions cypress.json

This file was deleted.

67 changes: 67 additions & 0 deletions cypress/e2e/auth/login.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

const username = Cypress.env('username');
const password = Cypress.env('password');

describe('Authentication scenarios', () => {
beforeEach(() => {
cy.visit('/');
});

it('Login to Swag Labs application', () => {
cy.get("input[id=user-name]").clear().type(username)
cy.get("input[id=password]").click().focused().clear().type(password)

cy.get("input[id=login-button]").click()

// Assert successful login
cy.url().should('include', '/inventory');
cy.get("div > a[data-test=shopping-cart-link]").should("be.visible")

})

it('should retain session after page reload', () => {
cy.get("input[id=user-name]").clear().type(username)
cy.get("input[id=password]").click().focused().clear().type(password)

cy.get("input[id=login-button]").click()

// Assert login
cy.url().should('include', '/inventory');

// Reload application page
cy.reload()

// Assert user still login
cy.url().should('include', '/inventory');
cy.get("div > a[data-test=shopping-cart-link]").should("be.visible")
})

it('should show error message on empty fields', () => {

// Click on login button and verify error message for username field
cy.get("input[id=login-button]").click()

cy.get("h3[data-test=error]").should("contain", "Epic sadface: Username is required")

// Insert username and click on login button. Verify error message for password field
cy.get("input[id=user-name]").clear().type(username)
cy.get("input[id=login-button]").click()
cy.get("h3[data-test=error]").should("contain", "Epic sadface: Password is required")
})

it('should show error message on wrong username and password values', () => {

// Assert input fields are empty initially
// cy.get(usernameField).should('be.empty');
// cy.get(passwordField).should('be.empty');

// Enter invalid credentials
cy.get("input[id=user-name]").clear().type("wrongUser")
cy.get("input[id=password]").clear().type("wrongPassword")
cy.get("input[id=login-button]").click()


const expectedError = "Epic sadface: Username and password do not match any user in this service"
cy.get("h3[data-test=error]").should("contain", expectedError)
})
})
43 changes: 43 additions & 0 deletions cypress/e2e/auth/logout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

const username = Cypress.env('username');
const password = Cypress.env('password');

describe('Authentication scenarios', () => {
beforeEach(() => {
cy.visit('/');

});

it('Logout from Swag Labs application', () => {
cy.get("input[id=user-name]").clear().type(username)
cy.get("input[id=password]").click().focused().clear().type(password)

cy.get("input[id=login-button]").click()

// logout from application
cy.get("button[id=react-burger-menu-btn]").click()
cy.get("a[id=logout_sidebar_link]").click()

// Assert successful logout
cy.get("input[id=login-button]").should("be.visible")
})

it('should logout after session expires', () => {
cy.get("input[id=user-name]").clear().type(username)
cy.get("input[id=password]").click().focused().clear().type(password)

cy.get("input[id=login-button]").click()

// Assert login
cy.url().should('include', '/inventory');

// clear cookies
cy.clearAllCookies()

// Load the page
cy.reload({force: true})

// Assert successful logout on session expiry
cy.get("input[id=login-button]").should("be.visible")
})
})
19 changes: 0 additions & 19 deletions cypress/integration/common.ts

This file was deleted.

3 changes: 0 additions & 3 deletions cypress/integration/constants.ts

This file was deleted.

12 changes: 0 additions & 12 deletions cypress/integration/models/products.ts

This file was deleted.

32 changes: 0 additions & 32 deletions cypress/integration/tests/cart.test.ts

This file was deleted.

41 changes: 0 additions & 41 deletions cypress/integration/tests/login.test.ts

This file was deleted.

6 changes: 0 additions & 6 deletions cypress/integration/views/login.view.ts

This file was deleted.

2 changes: 0 additions & 2 deletions cypress/integration/views/products.view.ts

This file was deleted.

21 changes: 0 additions & 21 deletions cypress/plugins/index.js

This file was deleted.

8 changes: 4 additions & 4 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
7 changes: 2 additions & 5 deletions cypress/support/index.js → cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ***********************************************************
// This example support/index.js is processed and
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
Expand All @@ -14,7 +14,4 @@
// ***********************************************************

// Import commands.js using ES2015 syntax:
import "./commands";

// Alternatively you can use CommonJS syntax:
// require('./commands')
import './commands'
15 changes: 0 additions & 15 deletions cypress/tsconfig.json

This file was deleted.

Loading

0 comments on commit b1485a5

Please sign in to comment.