|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +describe("Authentication Tests", () => { |
| 4 | + |
| 5 | + const testUser = { |
| 6 | + username: Cypress.env('testUsername'), |
| 7 | + email: Cypress.env('testUserEmail'), |
| 8 | + password: Cypress.env('testUserPassword') |
| 9 | + } |
| 10 | + |
| 11 | + beforeEach('visit the page and wait it to load', () => { |
| 12 | + |
| 13 | + cy.visit('/') |
| 14 | + |
| 15 | + cy.wait(1000) |
| 16 | + }) |
| 17 | + |
| 18 | + /** |
| 19 | + * @success |
| 20 | + */ |
| 21 | + it("Registers new user", () => { |
| 22 | + |
| 23 | + |
| 24 | + cy.get('[data-cy=btn-signin]').click() |
| 25 | + |
| 26 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 27 | + |
| 28 | + cy.get('[data-cy=link-create-account]').click() |
| 29 | + |
| 30 | + cy.url().should('equal', `${Cypress.config().baseUrl}/register`) |
| 31 | + |
| 32 | + cy.get('[data-cy=username]').type(testUser.username) |
| 33 | + |
| 34 | + cy.get('[data-cy=email]').type(testUser.email) |
| 35 | + |
| 36 | + cy.get('[data-cy=password]') |
| 37 | + .should('have.attr', 'type', 'password') |
| 38 | + .type(testUser.password) |
| 39 | + |
| 40 | + cy.get('[data-cy=tc]').click() |
| 41 | + |
| 42 | + cy.get('[data-cy=btn-register]').click() |
| 43 | + |
| 44 | + cy.url().should('equal', `${Cypress.config().baseUrl}/`) |
| 45 | + }) |
| 46 | + |
| 47 | + |
| 48 | + it("Signs in an existing user", () => { |
| 49 | + |
| 50 | + cy.get('[data-cy=btn-signin]').click() |
| 51 | + |
| 52 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 53 | + |
| 54 | + cy.wait(500) |
| 55 | + |
| 56 | + cy.get('[data-cy=login-username]').type(testUser.username) |
| 57 | + |
| 58 | + cy.get('[data-cy=login-password]').type(testUser.password) |
| 59 | + |
| 60 | + cy.get('[data-cy=login-btn]').click() |
| 61 | + |
| 62 | + cy.url().should('equal', `${Cypress.config().baseUrl}/`) |
| 63 | + |
| 64 | + }) |
| 65 | + |
| 66 | + |
| 67 | + /** |
| 68 | + * @failure |
| 69 | + */ |
| 70 | + it("Should not register using already registered credentials", () => { |
| 71 | + |
| 72 | + cy.get('[data-cy=btn-signin]').click() |
| 73 | + |
| 74 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 75 | + |
| 76 | + cy.get('[data-cy=link-create-account]').click() |
| 77 | + |
| 78 | + cy.url().should('equal', `${Cypress.config().baseUrl}/register`) |
| 79 | + |
| 80 | + cy.get('[data-cy=username]').type(testUser.username) |
| 81 | + |
| 82 | + cy.get('[data-cy=email]').type(testUser.email) //Using already registered email address |
| 83 | + |
| 84 | + cy.get('[data-cy=password]') |
| 85 | + .should('have.attr', 'type', 'password') |
| 86 | + .type(testUser.password) |
| 87 | + |
| 88 | + cy.get('[data-cy=tc]').click() |
| 89 | + |
| 90 | + cy.get('[data-cy=btn-register]').click() |
| 91 | + |
| 92 | + cy.contains("Email is already taken") |
| 93 | + }) |
| 94 | + |
| 95 | + it("Should not register using invalid details", () => { |
| 96 | + |
| 97 | + |
| 98 | + cy.get('[data-cy=btn-signin]').click() |
| 99 | + |
| 100 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 101 | + |
| 102 | + cy.get('[data-cy=link-create-account]').click() |
| 103 | + |
| 104 | + cy.url().should('equal', `${Cypress.config().baseUrl}/register`) |
| 105 | + |
| 106 | + cy.get('[data-cy=username]').type(testUser.username) |
| 107 | + |
| 108 | + cy.get('[data-cy=email]').type(Math.random() * 1000) //Invalid email address |
| 109 | + |
| 110 | + cy.get('[data-cy=password]') |
| 111 | + .should('have.attr', 'type', 'password') // Password not provided |
| 112 | + |
| 113 | + cy.get('[data-cy=tc]').click() |
| 114 | + |
| 115 | + cy.get('[data-cy=btn-register]').click() |
| 116 | + |
| 117 | + cy.contains("This is required") |
| 118 | + }) |
| 119 | + |
| 120 | + |
| 121 | + it("Should not register without agreeing to terms and conditions", () => { |
| 122 | + |
| 123 | + cy.get('[data-cy=btn-signin]').click() |
| 124 | + |
| 125 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 126 | + |
| 127 | + cy.get('[data-cy=link-create-account]').click() |
| 128 | + |
| 129 | + cy.url().should('equal', `${Cypress.config().baseUrl}/register`) |
| 130 | + |
| 131 | + cy.get('[data-cy=username]').type(testUser.username) |
| 132 | + |
| 133 | + cy.get('[data-cy=email]').type(Math.random() * 1000) |
| 134 | + |
| 135 | + cy.get('[data-cy=password]') |
| 136 | + .should('have.attr', 'type', 'password') |
| 137 | + .type(testUser.password) |
| 138 | + |
| 139 | + // Do not click on the checkbox |
| 140 | + |
| 141 | + cy.get('[data-cy=btn-register]').click() |
| 142 | + |
| 143 | + cy.contains("You must accept our Terms and Conditions") |
| 144 | + }) |
| 145 | + |
| 146 | + |
| 147 | + it("Should not login using invalid credentials", () => { |
| 148 | + |
| 149 | + cy.get('[data-cy=btn-signin]').click() |
| 150 | + |
| 151 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 152 | + |
| 153 | + cy.get('[data-cy=login-username]').type(testUser.username) |
| 154 | + |
| 155 | + cy.get('[data-cy=login-password]').type(Math.random() * 1000) //Invalid password |
| 156 | + |
| 157 | + cy.get('[data-cy=login-btn]').click() |
| 158 | + |
| 159 | + cy.contains("Identifier or password invalid") |
| 160 | + }) |
| 161 | + |
| 162 | +}) |
0 commit comments