Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress #192

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: End-to-end tests 🧪
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Node.js dependencies
run: npm ci
- name: Run Cypress tests
run: npx cypress run --config-file=cypress.config.js
8 changes: 8 additions & 0 deletions .vscode/mocha.tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "root",
"title": "root",
"file": null,
"state": "idle",
"tests": null,
"suites": null
}
15 changes: 15 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
video: true,
videoUploadOnPasses: false,
viewportHeight: 880,
viewportWidth: 1280,
// viewportHeight: 860,
// viewportWidth: 410,
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
275 changes: 275 additions & 0 deletions cypress/e2e/Cac-Tat.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
/// <reference types="Cypress"/>

describe('Central de Atendimento ao Cliente TAT', () => {


const THREE_SECONDS_IN_MS = 3000
beforeEach(() => {
cy.visit('./src/index.html')
})

it('verificar o titulo da aplicação', () => {
cy.title().should('be.equal', 'Central de Atendimento ao Cliente TAT')
})

it('Prenche os campos obrigatoriose envia o formulario', function () {
const longText = 'teste, teste, teste, teste, teste, teste, teste, teste, teste, teste, teste, teste'

cy.clock()

cy.get('#firstName').type('josep')
cy.get('#lastName').type('luca')
cy.get('#email').type('[email protected]')
cy.get('#phone').type('129681210')
cy.get('#open-text-area').type(longText, { delay: 0 })
cy.contains('button', 'Enviar').click()

cy.get('.success > strong').should('be.visible')

cy.tick(THREE_SECONDS_IN_MS)

cy.get('.success > strong').should('not.visible')

})

it('`exibe mensagem de erro ao submeter o formulário com um email com formatação inválida', () => {
cy.clock()

cy.get('#firstName').type('josep')
cy.get('#lastName').type('luca')
cy.get('#email').type('jklteste,com')
cy.get('#phone').type('129681210')
cy.get('#open-text-area').type('Teste', { delay: 0 })
cy.contains('button', 'Enviar').click()

cy.get('.error').should('be.visible')

cy.tick(THREE_SECONDS_IN_MS)

cy.get('.error').should('not.be.visible')
})


it('Campo telefone continua vazio quando prenchido com valor não númerico', () => {

cy.get('#phone')
.type('abcdefg')
.should('have.value', '')
})

it('exibe mensagem de erro quando o telefone se torna obrigatório mas não é preenchido antes do envio do formulário', () => {
cy.clock()

cy.get('#firstName').type('josep')
cy.get('#lastName').type('luca')
cy.get('#email').type('[email protected]')
cy.get('#phone-checkbox').check()
cy.get('#open-text-area').type('Teste')
cy.contains('button', 'Enviar').click()

cy.get('.error').should('be.visible')

cy.tick(THREE_SECONDS_IN_MS)

cy.get('.error').should('not.be.visible')

})

it('preenche e limpa os campos nome, sobrenome, email e telefone', () => {
cy.get('#firstName')
.type('josep')
.should('have.value', 'josep')
.clear()
.should('have.value', '')

cy.get('#lastName')
.type('luca')
.should('have.value', 'luca')
.clear()
.should('have.value', '')

cy.get('#email')
.type('[email protected]')
.should('have.value', '[email protected]')
.clear()
.should('have.value', '')

cy.get('#phone')
.type('129681210')
.should('have.value', '129681210')
.clear()
.should('have.value', '')

})

it('exibe mensagem de erro ao submeter o formulário sem preencher os campos obrigatórios', () => {
cy.clock()

cy.contains('button', 'Enviar').click()

cy.get('.error').should('be.visible')

cy.tick(THREE_SECONDS_IN_MS)

cy.get('.error').should('not.be.visible')

})

it('envia o formuário com sucesso usando um comando customizado', () => {

cy.clock()

cy.fillMandatoryFieldsAndSubmit()

cy.get('.success').should('be.visible')

cy.tick(THREE_SECONDS_IN_MS)

cy.get('.success').should('not.be.visible')

})

it('seleciona um produto (YouTube) por seu texto', () => {

cy.get('#product')
.select('YouTube')
.should('have.value', 'youtube')
})
it('seleciona um produto (Mentoria) por seu valor (value)', () => {

cy.get('#product')
.select('mentoria')
.should('have.value', 'mentoria')
})

it('seleciona um produto (Blog) por seu índice', () => {

cy.get('#product')
.select(1)
.should('have.value', 'blog')
})

it('marca o tipo de atendimento "Feedback', () => {

cy.get('input[type="radio"][value="feedback"]')
.check()
.should('have.value', 'feedback')
})

it(' marca cada tipo de atendimento', () => {

cy.get('input[type="radio"]')
.should('have.length', 3)
.each(function ($radio) {
cy.wrap($radio).check()
cy.wrap($radio).should('be.checked')

})
})

it('marca ambos checkboxes, depois desmarca o último', () => {

cy.get('input[type="checkbox"]')
.check()
.should('be.checked')
.last()
.uncheck()
.should('not.be.checked')
})

it('seleciona um arquivo da pasta fixtures', () => {

cy.get('input[type="file"]')
.should('not.have.value')
.selectFile('./cypress/fixtures/example.json')
.should(function ($input) {
expect($input[0].files[0].name).to.equal('example.json')
})
})

it('seleciona um arquivo simulando um drag-and-drop', () => {

cy.get('input[type="file"]').
should('not.have.value')
.selectFile('./cypress/fixtures/example.json', { action: 'drag-drop' })
.should(function ($input) {
expect($input[0].files[0].name).to.equal('example.json')
})
})

it('seleciona um arquivo utilizando uma fixture para a qual foi dada um alias', () => {

cy.fixture('example.json').as('sampleFile')
cy.get('input[type="file"]')
.selectFile('@sampleFile')
.should(function ($input) {
expect($input[0].files[0].name).to.equal('example.json')

})
})
it('verifica que a política de privacidade abre em outra aba sem a necessidade de um clique', () => {

cy.get('#privacy a').should('have.attr', 'target', '_blank')
})

it('acessa a página da política de privacidade removendo o target e então clicando no link', () => {

cy.get('#privacy a')
.invoke('removeAttr', 'target')
.click()

cy.contains('Talking About Testing').should('be.visible')

})

it('exibe e esconde as mensagens de sucesso e erro usando o .invoke', () => {
cy.get('.success')
.should('not.be.visible')
.invoke('show')
.should('be.visible')
.and('contain', 'Mensagem enviada com sucesso.')
.invoke('hide')
.should('not.be.visible')

cy.get('.error')
.should('not.be.visible')
.invoke('show')
.should('be.visible')
.and('contain', 'Valide os campos obrigatórios!')
.invoke('hide')
.should('not.be.visible')
})

it('preenche a area de texto usando o comando invoke', () => {
const longText = Cypress._.repeat('text', 20)

cy.get('#open-text-area')
.invoke('val', longText)
.should('have.value', longText)

})

it('faz uma requisicao HTTP', () => {
cy.request('https://cac-tat.s3.eu-central-1.amazonaws.com/index.html')
.should(function (response) {
const { status, statusText, body } = response
expect(status).to.equal(200)
expect(statusText).to.equal('OK')
expect(body).to.include('CAC TAT')

})
})

it('Encontre o gato escondido', () => {
cy.get('#cat')
.invoke('show')
.should('be.visible')

cy.get('#title')
.invoke('text', 'CAC TAT')

cy.get('#subtitle')
.invoke('text', 'Eu 💚 gatos!')
})

})
6 changes: 6 additions & 0 deletions cypress/e2e/privacy.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Cypress._.times(5, function () {
it('testa a página da política de privacidade de forma independente', () => {
cy.visit('./src/privacy.html')
cy.contains('Talking About Testing').should('be.visible')
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
35 changes: 35 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

Cypress.Commands.add('fillMandatoryFieldsAndSubmit', () => {

cy.get('#firstName').type('josep')
cy.get('#lastName').type('luca')
cy.get('#email').type('[email protected]')
cy.get('#phone').type('129681210')
cy.get('#open-text-area').type('Teste')
cy.contains('button', 'Enviar').click()
})
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading