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

Lessons 0-2 #209

Open
wants to merge 2 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
9 changes: 9 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
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"
}
149 changes: 149 additions & 0 deletions cypress/integration/CAC-TAT.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// CAC-TAT.spec.js created with Cypress
//
// Start writing your Cypress tests below!
// If you're unfamiliar with how Cypress works,
// check out the link below and learn how to write your first test:
// https://on.cypress.io/writing-first-test

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

beforeEach(() => {
cy.visit('./src/index.html');
})

it('verifica o título da aplicação', function(){
cy.title().should('equal','Central de Atendimento ao Cliente TAT');
})

it('preenche os campos obrigatórios e envia o formulário', function () {
//Criando uma variável para repetir um texto
const longText = Cypress._.repeat('Lorem ipsum dolor sit amet',15);

//Ação
cy.get('#firstName').type('Lucas');
cy.get('#lastName').type('Costa Milagres').should('have.value','Costa Milagres',);
cy.get('#email').type('[email protected]').should('include.value','lucas');
cy.get('#open-text-area').type(longText,{delay:0});
cy.get('button[type="submit"]').click();

//Resultado esperado
cy.get('.success').should('be.visible');
})

it('exibe mensagem de erro ao submeter o formulário com um email com formatação inválida', function(){
//Ação
cy.get('#firstName').type('Lucas');
cy.get('#lastName').type('Costa Milagres');
cy.get('#email').type('emailinválido');
cy.get('#open-text-area').type('Teste');
cy.contains('button', 'Enviar').click();

//Resultado esperado
cy.get('.error').should('be.visible');
})

it('campo telefone continua vazio quando preenchido com um valor não-numérico', () => {
cy.get('#phone')
.type('Lucas.,;~][´\!@#$%¨&*()-=')
.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.get('#firstName').type('Lucas');
cy.get('#lastName').type('Costa Milagres');
cy.get('#email').type('[email protected]');
cy.get('#open-text-area').type('Teste');
cy.get('#phone-checkbox').check();
cy.contains('.button', 'Enviar').click();

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

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

cy.get('#lastName')
.type('Costa Milagres')
.should('have.value','Costa Milagres')
.clear()
.should('have.value','');

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

cy.get('#phone')
.type('11942563100')
.should('have.value','11942563100')
.clear()
.should('have.value','');
})

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

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

it('envia o formuário com sucesso usando um comando customizado', () => {
const data = {
firstName: 'Lucas',
lastName: 'Costa Milagres',
email: '[email protected]',
phone: '11912345678',
text: 'Texto de teste'
}

cy.fillMandatoryFieldsAndSubmit(data);

cy.get('.success').should('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('seleciona um produto por seu índice de forma aleatória', () => {
cy.get('select option')
.not('[disabled]')
.its('length', { log: false }).then(n => {
cy.get('#product').select(Cypress._.random(n - 1));
})
})

it('marca o tipo de atendimento "Feedback"(Busca mais genérica)', () => {
cy.get('[type="radio"]').check('feedback');

cy.get('#support-type :checked').should('be.checked').and('have.value', 'feedback');
})

it('marca o tipo de atendimento "Feedback" (Busca mais específica)', () => {
cy.get('input[type="radio"][value="ajuda"]').check()
.should('be.checked');
})

it('marca cada tipo de atendimento', () => {
cy.get('[type="radio"]').each(typeOfService => {
cy.wrap(typeOfService)
.check()
.should('be.checked');
})
})
})
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
38 changes: 38 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ***********************************************
// 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', (data = {
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
text: 'Test'
}) => {
cy.get('#firstName').type(data.firstName);
cy.get('#lastName').type(data.lastName);
cy.get('#email').type(data.email);
cy.get('#open-text-area').type(data.text);
cy.contains('button', 'Enviar').click();
})
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.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')
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Repositório da versão 2 do curso básico de Cypress da Escola Talking About Testing",
"main": "src/index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"cy:open": "cypress open",
"test": "cypress run"
},
"repository": {
"type": "git",
Expand Down