Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: End-to-end tests 🧪
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cypress run
uses: cypress-io/github-action@v6
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
with:
command: npm run test:cloud
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({
viewportHeight: 880,
viewportWidth: 1280,
projectId: "zwzzaq",
e2e: {},
video: true
})
185 changes: 185 additions & 0 deletions cypress/e2e/CAC-TAT.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
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('lucasmilagres@teste.com').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('lucas@teste.com');
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('lucas@teste.com')
.should('have.value','lucas@teste.com')
.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: 'lucas@teste.com',
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(1, n));
})
})

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');
})
})

it('marca ambos checkboxes, depois desmarca o último', () => {
cy.get('#check input[type="checkbox"]').as('checkboxs').check().should('be.checked')

cy.get('@checkboxs').last().uncheck().should('not.be.checked');
})

it('seleciona um arquivo da pasta fixtures', () => {
cy.get('#file-upload')
.selectFile('cypress/fixtures/example.json')
.should(input => {
expect(input[0].files[0].name).to.equal('example.json')
})
})

it('seleciona um arquivo simulando um drag-and-drop', () => {
cy.get('#file-upload')
.selectFile('cypress/fixtures/example.json', { action: 'drag-drop'})
.then(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('#file-upload').selectFile('@sampleFile')
.then(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.contains('a', 'Política de Privacidade')
.should('have.attr', 'href', 'privacy.html')
.and('have.attr', 'target', '_blank');
})

it('acessa a página da política de privacidade removendo o target e então clicando no link', () => {
cy.contains('a', 'Política de Privacidade').invoke('removeAttr','target').click();

cy.contains('h1','CAC TAT - Política de privacidade').should('be.visible');
})

})
8 changes: 8 additions & 0 deletions cypress/e2e/pravacyPolicy.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
describe('CAC TAT - Política de privacidade', function() {
it.only('testa a página da política de privacidade de forma independente', () => {
cy.visit('./src/privacy.html');

cy.contains('h1','CAC TAT - Política de privacidade').should('be.visible');
cy.contains('p','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": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
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: 'johndoe@example.com',
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/e2e.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')
41 changes: 41 additions & 0 deletions lessons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 🌲 Cypress, from Zero to the Cloud ☁️

Sample project for the "Cypress, from Zero to the Cloud" course of the Talking about Testing online school.

## Pre-requirements

It is required to have Node.js and npm installed to run this project.

> I used versions `2.42.1`, `v20.13.1` and `10.8.1` of Node.js and npm, respectively. I suggest you use the same or later versions.

## Installation

Run `npm install` (or `npm i` for the short version) to install the dev dependencies.

## Tests

In this project, you can run the tests on a desktop or a mobile viewport.

## Desktop

Run `npm test` (or `npm t` for the short version) to run the test in headless mode.

Or, run `npm run cy:open` to open Cypress in interactive mode.

## Mobile

Run `npm run test:mobile` to run the test in headless mode on a mobile viewport.

Or, run `npm run cy:open:mobile` to open Cypress in interactive mode.


## Support this project

If you want to support this project, leave a ⭐.
___

Vá para a seção [estrutura do curso](./_course-structure_.md).

___

Este é mais um curso da [**Escola Talking About Testing**](https://udemy.com/user/walmyr).
Loading