Skip to content
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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Dependências do Node
node_modules/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Diretórios de build
dist/
build/
# Dependências do Cypress
.cypress_cache/
# Arquivos de sistema operacional
.DS_Store
Thumbs.db
# Configurações do editor
.idea/
.vscode/
# Ambiente
.env

#reports
reports/
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,58 @@ Certifique-se de que seu pull request está sendo enviado no link do formulário

Estou ansioso para ver sua abordagem criativa e eficiente para este desafio de testes automatizados.
Boa sorte!

----

# Projeto de Automação de Testes E2E com Cypress

Descrição: Este projeto feito com o Cypress, um framework de testes end-to-end, para automatizar testes em aplicações web. Utilização também do Faker para gerar dados de teste realistas, como nomes, endereços e CPFs.

# Tecnologias Utilizadas

Cypress: Framework de testes E2E

Versão: ^13.13.0

@testing-library/cypress: Biblioteca para auxiliar na escrita de testes mais robustos e acessíveis

Versão: ^10.0.2

@faker-js/faker: Biblioteca para gerar dados falsos

Versão: ^8.4.1

gerador-validador-cpf: Biblioteca para gerar CPFs válidos

Versão: ^5.0.2

ESLint: Ferramenta para análise estática de código JavaScript

Versão: ^9.7.0

eslint-plugin-cypress: Plugin do ESLint com regras específicas para o Cypress

Versão: ^3.3.0

---

# Pré-requisitos

Gerenciador de Pacotes (npm ou yarn): Certifique-se de ter um gerenciador de pacotes instalado. O npm geralmente vem junto com
o Node.js.

Node.js versão: `v20.11.1` - node -v

Executando os Testes local: `npx cypress open `

Modo Headless: `npx cypress run`

Isso executará todos os testes em modo headless (sem interface gráfica).

# Observações

Faker: O Faker é usado para gerar dados aleatórios nos testes. Lógica esta em `dataGenerator.js`

Cypress Testing Library: Utilize os comandos da Cypress Testing Library para escrever testes mais robustos e acessíveis quando não se tem o campo data-cy.

Validação de CPF: O pacote `gerador-validador-cpf` é usado para gerar CPFs válidos nos testes.
19 changes: 19 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({

reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
reportDir: 'cypress/reports',
overwrite: false,
html: true,
json: true,
timestamp: 'mmddyyyy_HHMMss',
},

e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
34 changes: 34 additions & 0 deletions cypress/e2e/cadastro/validar_cadastro.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { generateUserData } = require('../../support/dataGenerator');

describe('Dado que usuário deseja realizar um cadastro, Quando preencher o formulário, Então deve ser redirecionado para uma tela de sucesso', () => {
beforeEach(() => {
cy.visit('https://qastage.buildbox.one/18/cadastro/');
});

it('Validar o cadastro de um novo usuário com sucesso', () => {
const userData = generateUserData();

cy.get('[data-cy="button-btn-enroll"]').click();
cy.get('[data-cy="input-signup-personal-data-firstName"]').type(userData.firstName);
cy.get('[data-cy="input-signup-personal-data-lastName"]').type(userData.lastName);
cy.get('[data-cy="input-signup-personal-data-birthDate"]').type(userData.formattedBirthDate);
cy.get('[data-cy="input-signup-personal-data-cpf"]').type(userData.validCpf);
cy.get('[data-cy="input-signup-personal-data-email"]').type(userData.email);
cy.get('[data-cy="input-signup-personal-data-email-confirm"]').type(userData.email);
cy.get('[data-cy="input-signup-personal-data-password"]').type(userData.password);
cy.get('[data-cy="input-signup-personal-data-password-confirm"]').type(userData.password);

cy.get('button[type="button"][aria-controls="dropdown-button-1"]').should('be.visible').click();
cy.findByText('Beginner').should('be.visible').click();
cy.wait(2000);
cy.get('[data-cy="input-signup-personal-data-lgpd"]').click();
cy.get('[data-cy="button-signup_submit_button_1"]').click();
cy.get('[data-cy="input-signup-address-neighborhood"]').type('Cristo Redentor');
cy.get('[data-cy="input-signup-address-cep"]').type('91350240');
cy.get('[data-cy="input-signup-address-number"]').type('54');
cy.get('[data-cy="input-signup-address-complement"]').type('Apto lar 1');
cy.get('[data-cy="button-signup_submit_button_3"]').should('be.visible').click();
cy.wait(2000);
cy.contains('Thank you for joining us!').should('exist');
});
});
31 changes: 31 additions & 0 deletions cypress/e2e/cadastro/validar_cadastro_negativo.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { generateUserData } = require('../../support/dataGenerator');
const { generateExistingUserData } = require('../../support/dataGenerator');

Cypress.on('uncaught:exception', (_err, _runnable) => {
return false;
});

describe('Dado que usuário deseja realizar um cadastro, Quando preencher o formulário, Então deve ser redirecionado para uma tela de sucesso', () => {
beforeEach(() => {
cy.visit('https://qastage.buildbox.one/18/cadastro/');
});

it('Deve exibir erro quando tentar cadastrar com Dados já existente', () => {
const existingUserData = generateExistingUserData();

cy.get('[data-cy="button-btn-enroll"]').click();
cy.get('[data-cy="input-signup-personal-data-firstName"]').type(existingUserData.firstName);
cy.get('[data-cy="input-signup-personal-data-lastName"]').type(existingUserData.lastName);
cy.get('[data-cy="input-signup-personal-data-birthDate"]').type(existingUserData.formattedBirthDate);
cy.get('[data-cy="input-signup-personal-data-cpf"]').type(existingUserData.cpf);
cy.get('[data-cy="input-signup-personal-data-email"]').type(existingUserData.email);
cy.get('[data-cy="input-signup-personal-data-email-confirm"]').type(existingUserData.email);
cy.get('[data-cy="input-signup-personal-data-password"]').type(existingUserData.password);
cy.get('[data-cy="input-signup-personal-data-password-confirm"]').type(existingUserData.password);
cy.get('[data-cy="input-signup-personal-data-lgpd"]').click();
cy.get('[data-cy="button-signup_submit_button_1"]').click();
cy.contains('CPF inválido.').should('be.visible');
cy.contains('Este email já está em uso.').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"
}
26 changes: 26 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ***********************************************
// 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) => { ... })
import '@testing-library/cypress/add-commands'
37 changes: 37 additions & 0 deletions cypress/support/dataGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { faker } = require('@faker-js/faker');
const cpf = require('gerador-validador-cpf');

function generateUserData() {
const firstName = faker.name.firstName();
const lastName = faker.name.lastName();
const birthDate = faker.date.birthdate({ min: 18, max: 65, mode: 'age' });
const formattedBirthDate = ('0' + birthDate.getDate()).slice(-2) + ('0' + (birthDate.getMonth() + 1)).slice(-2) + birthDate.getFullYear();
const validCpf = cpf.generate();
const email = faker.internet.email();
const password = faker.internet.password();

return {
firstName,
lastName,
formattedBirthDate,
validCpf,
email,
password,
};
}

function generateExistingUserData() {
return {
firstName: 'João',
lastName: 'Silva',
formattedBirthDate: '01011990',
cpf: '123.456.789-00',
email: '[email protected]',
password: 'senhaForte123'
};
}

module.exports = {
generateUserData,
generateExistingUserData
};
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