diff --git a/test/pages/login.page.js b/test/pages/login.page.js new file mode 100644 index 0000000..c60a16e --- /dev/null +++ b/test/pages/login.page.js @@ -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() diff --git a/test/specs/example.e2e.js b/test/specs/example.e2e.js deleted file mode 100644 index 29e4053..0000000 --- a/test/specs/example.e2e.js +++ /dev/null @@ -1,14 +0,0 @@ -describe('My Login application', () => { - it('should login with valid credentials', async () => { - await browser.url(`https://the-internet.herokuapp.com/login`) - - await $('#username').setValue('tomsmith') - await $('#password').setValue('SuperSecretPassword!') - await $('button[type="submit"]').click() - - await expect($('#flash')).toBeExisting() - await expect($('#flash')).toHaveTextContaining( - 'You logged into a secure area!') - }) -}) - diff --git a/test/specs/login.e2e.js b/test/specs/login.e2e.js index 29e4053..81ebc92 100644 --- a/test/specs/login.e2e.js +++ b/test/specs/login.e2e.js @@ -1,14 +1,21 @@ -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', () => { + it('signs in with valid credentials', async () => { + await browser.url('/') - await expect($('#flash')).toBeExisting() - await expect($('#flash')).toHaveTextContaining( - 'You logged into a secure area!') + await LoginPage.fillSubmitForm('generic@email.com', 'generic') + + await expect(browser).toHaveUrlContaining('home') + await expect($('h1')).toHaveTextContaining('Serverest Store') + }) + + it('shows error message with wrong password', async () => { + await browser.url('/') + + await LoginPage.fillSubmitForm('generic@email.com', 'wrong') + + await expect($('.alert')).toHaveTextContaining('Email e/ou senha inválidos') }) })