From 6249ebdf24c71697666d95d0acaf101bc5008214 Mon Sep 17 00:00:00 2001 From: lorainegarutti Date: Mon, 20 Mar 2023 14:03:12 -0300 Subject: [PATCH 1/2] Add automated test cases for login feature --- test/pages/login.page.js | 15 +++++++++++++++ test/specs/example.e2e.js | 14 -------------- test/specs/login.e2e.js | 25 ++++++++++++++++--------- 3 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 test/pages/login.page.js delete mode 100644 test/specs/example.e2e.js 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') }) }) From 8fd6c5d442eebd0107da6839f07d6503a434ebaa Mon Sep 17 00:00:00 2001 From: lorainegarutti Date: Mon, 20 Mar 2023 14:13:53 -0300 Subject: [PATCH 2/2] Create CI to run e2e automated tests --- .github/e2e-tests.yml | 27 +++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .github/e2e-tests.yml diff --git a/.github/e2e-tests.yml b/.github/e2e-tests.yml new file mode 100644 index 0000000..639d72b --- /dev/null +++ b/.github/e2e-tests.yml @@ -0,0 +1,27 @@ +name: End-to-end + +on: + pull_request: + +jobs: + e2e_tests: + name: End-to-end tests run + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Use specific node version + uses: actions/setup-node@v3 + with: + node-version: '16.x' + cache: 'yarn' + + - name: Install dependencies + run: yarn install + shell: bash + + - name: Run end-to-end tests + run: yarn run test:e2e + + - name: Generate end-to-end tests report + run: yarn run test:generate:report diff --git a/package.json b/package.json index 00b4b9e..1c61aeb 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,6 @@ }, "scripts": { "test:e2e": "wdio run ./wdio.conf.js --spec ./test/specs/*.e2e.js", - "test:generate:report": "marge ./test/results/wdio-ma-merged.json --reportTitle 'End-to-end tests report' --reportDir ./test/results --reportFilename 'e2e-report'" + "test:generate:report": "marge ./test/results/results-0-0.json --reportTitle 'End-to-end tests report' --reportDir ./test/results --reportFilename 'e2e-report'" } }