diff --git a/cypress/e2e/features/Login.feature b/cypress/e2e/features/Login.feature new file mode 100644 index 0000000..36ff8ec --- /dev/null +++ b/cypress/e2e/features/Login.feature @@ -0,0 +1,22 @@ +Feature: Login + As a user + I want to sign in + I want to benoticed when sign in fails + + Background: + Given The web browser is at the login page + + Scenario: Successful Login + When I submit the credentials 'tomsmith' 'SuperSecretPassword!' + Then I am on the welcome page + + # Scenario: Refresh and stay logged in + # Given I am logged in as "peter-pan" + # When I refresh the page + # Then I am logged in with username "Peter Pan" + + # Scenario: Log out + # Given I am logged in as "peter-pan" + # When I navigate to page "/" + # And I log out + # Then I am on page "login" \ No newline at end of file diff --git a/cypress/e2e/step_definitions/login.ts b/cypress/e2e/step_definitions/login.ts new file mode 100644 index 0000000..0754143 --- /dev/null +++ b/cypress/e2e/step_definitions/login.ts @@ -0,0 +1,21 @@ +import { + Given, + When, + Then, +} from '@badeball/cypress-cucumber-preprocessor' +import {loginPage} from '../../pages/LoginPage' +import {welcomePage} from '../../pages/WelcomePage' + +Given('The web browser is at the login page', () => { + cy.visit('/login') +}) + +When('I submit the credentials {string} {string}', (username:string, password: string) => { + loginPage.submitLogin(username, password) +}) + +Then('I am on the welcome page', () => { + cy.get(welcomePage.successMessage).should('be.visible') + cy.get(welcomePage.WelcomeHeader).should('be.visible') + cy.get(welcomePage.logoutBtn).should('be.visible') +}) \ No newline at end of file diff --git a/cypress/pages/LoginPage.ts b/cypress/pages/LoginPage.ts new file mode 100644 index 0000000..1279fc1 --- /dev/null +++ b/cypress/pages/LoginPage.ts @@ -0,0 +1,13 @@ +class LoginPage { + usernameInput: string = '#username' + passwordInput:string = '#password' + submitBtn: string = 'button[type=submit]' + + submitLogin(username: string, password: string){ + cy.get(this.usernameInput).type(username) + cy.get(this.passwordInput).type(password) + cy.get(this.submitBtn).click() + } +} + +export const loginPage = new LoginPage() \ No newline at end of file diff --git a/cypress/pages/WelcomePage.ts b/cypress/pages/WelcomePage.ts new file mode 100644 index 0000000..885c6b9 --- /dev/null +++ b/cypress/pages/WelcomePage.ts @@ -0,0 +1,7 @@ +class WelcomePage { + successMessage: string = '.flash.success' + WelcomeHeader:string = '.subheader' + logoutBtn: string = 'a[href="/logout"]' +} + +export const welcomePage = new WelcomePage() \ No newline at end of file