Skip to content

Commit

Permalink
Add automated test cases for login feature
Browse files Browse the repository at this point in the history
  • Loading branch information
lorainegarutti committed Mar 20, 2023
1 parent 0cd6e06 commit 251ccda
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
15 changes: 15 additions & 0 deletions test/pages/login.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class LoginPage {

get username () { return $('#email') }
get password () { return $('#password') }
get enterBtn () { return $('button=Entrar') }

async fillSubmitForm (user, pass) {
await this.username.setValue(user)
await this.password.setValue(pass)
await this.enterBtn.click()
}

}

export default new LoginPage()
14 changes: 0 additions & 14 deletions test/specs/example.e2e.js

This file was deleted.

26 changes: 16 additions & 10 deletions test/specs/login.e2e.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
describe('My Login application', () => {
it('should login with valid credentials', async () => {
await browser.url(`https://the-internet.herokuapp.com/login`)
import LoginPage from '../pages/login.page.js'

await $('#username').setValue('tomsmith')
await $('#password').setValue('SuperSecretPassword!')
await $('button[type="submit"]').click()
describe('Application login', () => {
beforeEach(async () => {
await browser.url('/')
})

it('signs in with valid credentials', async () => {
await LoginPage.fillSubmitForm('[email protected]', 'generic')

await expect($('#flash')).toBeExisting()
await expect($('#flash')).toHaveTextContaining(
'You logged into a secure area!')
await expect(browser).toHaveUrlContaining('home')
await expect($('h1')).toHaveTextContaining('Serverest Store')
})
})

it('shows error message with wrong password', async () => {
await LoginPage.fillSubmitForm('[email protected]', 'wrong')

await expect($('.alert')).toHaveTextContaining('Email e/ou senha inválidos')
})
})

0 comments on commit 251ccda

Please sign in to comment.