-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Work with alerts', () => { | ||
beforeEach(() => { | ||
cy.visit('https://wcaquino.me/cypress/componentes.html') | ||
}) | ||
|
||
beforeEach(() => { | ||
cy.reload() | ||
}) | ||
|
||
it('Alert', () => { | ||
// cy.get('#alert').click() | ||
// cy.on('window:alert', msg => { | ||
// expect(msg).to.be.equal('Alert Simples') | ||
// }) | ||
cy.clickAlert('#alert', 'Alert Simples') | ||
}) | ||
|
||
it('Alert com mock', () => { | ||
const stub = cy.stub().as('alerta') | ||
cy.on('window:alert', stub) | ||
cy.get('#alert').click().then(() => { | ||
expect(stub.getCall(0)).to.be.calledWith('Alert Simples') | ||
}) | ||
}) | ||
|
||
it('Confirm', () => { | ||
cy.on('window:confirm', msg => { | ||
expect(msg).to.be.equal('Confirm Simples') | ||
}) | ||
cy.on('window:alert', msg => { | ||
expect(msg).to.be.equal('Confirmado') | ||
}) | ||
cy.get('#confirm').click() | ||
}) | ||
|
||
it('Deny', () => { | ||
cy.on('window:confirm', msg => { | ||
expect(msg).to.be.equal('Confirm Simples') | ||
return false | ||
}) | ||
cy.on('window:alert', msg => { | ||
expect(msg).to.be.equal('Negado') | ||
}) | ||
cy.get('#confirm').click() | ||
}) | ||
|
||
it('Prompt', () => { | ||
cy.window().then(win => { | ||
cy.stub(win, 'prompt').returns('42') | ||
}) | ||
cy.on('window:confirm', msg => { | ||
expect(msg).to.be.equal('Era 42?') | ||
}) | ||
cy.on('window:alert', msg => { | ||
expect(msg).to.be.equal(':D') | ||
}) | ||
cy.get('#prompt').click() | ||
}) | ||
|
||
it('Validando mensagens', () => { | ||
const stub = cy.stub().as('alerta') | ||
cy.on('window:alert', stub) | ||
cy.get('#formCadastrar').click() | ||
.then(() => expect(stub.getCall(0)).to.be.calledWith('Nome eh obrigatorio')) | ||
|
||
cy.get('#formNome').type('Wagner') | ||
cy.get('#formCadastrar').click() | ||
.then(() => expect(stub.getCall(1)).to.be.calledWith('Sobrenome eh obrigatorio')) | ||
|
||
cy.get('[data-cy=dataSobrenome]').type('Aquino') | ||
cy.get('#formCadastrar').click() | ||
.then(() => expect(stub.getCall(2)).to.be.calledWith('Sexo eh obrigatorio')) | ||
|
||
cy.get('#formSexoMasc').click() | ||
cy.get('#formCadastrar').click() | ||
|
||
cy.get('#resultado > :nth-child(1)').should('contain', 'Cadastrado!') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
it('nada agora', function () { }) | ||
|
||
// function soma(a, b) { | ||
// return a + b; | ||
// } | ||
|
||
// const soma = function (a, b) { | ||
// return a + b | ||
// } | ||
|
||
// const soma = (a, b) => { | ||
// return a + b | ||
// } | ||
|
||
// const soma = (a, b) => a + b | ||
|
||
// const soma = (a, b) => { | ||
// return a + b | ||
// } | ||
|
||
// const soma = (a) => a + a | ||
|
||
// const soma = a => a + a | ||
|
||
const soma = () => 5 + 5 | ||
|
||
console.log(soma(1, 4)) | ||
|
||
it('a fuction test...', function () { | ||
console.log('Function', this) | ||
}) | ||
|
||
it('an arrow test...', () => { | ||
console.log('Arrow', this) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/// <reference types="cypress" /> | ||
|
||
it('Equality', () => { | ||
const a = 1; | ||
|
||
expect(a).equal(1); | ||
expect(a, 'Deveria ser 1').equal(1); | ||
expect(a).to.be.equal(1); | ||
expect('a').not.to.be.equal('b') | ||
}) | ||
|
||
it('Truthy', () => { | ||
const a = true; | ||
const b = null; | ||
let c; | ||
|
||
expect(a).to.be.true; | ||
expect(true).to.be.true; | ||
expect(b).to.be.null; | ||
expect(a).to.be.not.null; | ||
expect(c).to.be.undefined; | ||
}) | ||
|
||
it('Object Equality', () => { | ||
const obj = { | ||
a: 1, | ||
b: 2 | ||
} | ||
|
||
expect(obj).equal(obj) | ||
expect(obj).equals(obj) | ||
expect(obj).eq(obj) | ||
expect(obj).to.be.equal(obj) | ||
expect(obj).to.be.deep.equal({ a: 1, b: 2 }) | ||
expect(obj).eql({ a: 1, b: 2 }) | ||
expect(obj).include({ a: 1 }) | ||
expect(obj).to.have.property('b') | ||
expect(obj).to.have.property('b', 2) | ||
expect(obj).to.not.be.empty | ||
expect({}).to.be.empty | ||
}) | ||
|
||
it('Arrays', () => { | ||
const arr = [1, 2, 3] | ||
expect(arr).to.have.members([1, 2, 3]) | ||
expect(arr).to.include.members([1, 3]) | ||
expect(arr).to.not.be.empty | ||
expect([]).to.be.empty | ||
}) | ||
|
||
it('Types', () => { | ||
const num = 1 | ||
const str = 'String' | ||
|
||
expect(num).to.be.a('number') | ||
expect(str).to.be.a('string') | ||
expect({}).to.be.an('object') | ||
expect([]).to.be.an('array') | ||
}) | ||
|
||
it('String', () => { | ||
const str = 'String de teste' | ||
|
||
expect(str).to.be.equal('String de teste') | ||
expect(str).to.have.length(15) | ||
expect(str).to.contains('de') | ||
expect(str).to.match(/de/) | ||
expect(str).to.match(/^String/) | ||
expect(str).to.match(/teste$/) | ||
expect(str).to.match(/.{15}/) | ||
expect(str).to.match(/\w+/) | ||
expect(str).to.match(/\D+/) | ||
}) | ||
|
||
it('Numbers', () => { | ||
const number = 4 | ||
const floatNumber = 5.2123 | ||
|
||
expect(number).to.be.equal(4) | ||
expect(number).to.be.above(3) | ||
expect(number).to.be.below(7) | ||
expect(floatNumber).to.be.equal(5.2123) | ||
expect(floatNumber).to.be.closeTo(5.2, 0.1) | ||
expect(floatNumber).to.be.above(5) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Cypress basics', () => { | ||
it('Should visit a page and assert title', () => { | ||
cy.visit('https://wcaquino.me/cypress/componentes.html') | ||
|
||
// const title = cy.title() | ||
// console.log(title) | ||
|
||
cy.title().should('be.equal', 'Campo de Treinamento') | ||
cy.title().should('contain', 'Campo') | ||
|
||
cy.title() | ||
.should('be.equal', 'Campo de Treinamento') | ||
.and('contain', 'Campo') | ||
|
||
let syncTitle | ||
|
||
cy.title().then(title => { | ||
console.log(title) | ||
|
||
cy.get('#formNome').type(title) | ||
|
||
syncTitle = title | ||
}) | ||
|
||
cy.get('[data-cy=dataSobrenome]').then($el => { | ||
$el.val(syncTitle) | ||
}) | ||
|
||
cy.get('#elementosForm\\:sugestoes').then($el => { | ||
cy.wrap($el).type(syncTitle) | ||
}) | ||
}) | ||
|
||
it('Should find and interact with an element', () => { | ||
cy.visit('https://wcaquino.me/cypress/componentes.html') | ||
|
||
// cy.get('nao existe') | ||
cy.get('#buttonSimple') | ||
.click() | ||
.should('have.value', 'Obrigado!') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference types="cypress" /> | ||
|
||
it('A external test...', () => { | ||
|
||
}) | ||
|
||
describe('Should group tests...', () => { | ||
describe('Should group more specific tests...', () => { | ||
it('A specific test...', () => { | ||
|
||
}) | ||
}) | ||
|
||
describe('Should group more specific tests 2...', () => { | ||
it('A specific test 2 ...', () => { | ||
|
||
}) | ||
}) | ||
|
||
|
||
it('A internal test...', () => { | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// <reference types="cypress" /> | ||
|
||
describe('Dinamic tests', () => { | ||
beforeEach(() => { | ||
cy.visit('https://wcaquino.me/cypress/componentes.html') | ||
}) | ||
|
||
const foods = ['Carne', 'Frango', 'Pizza', 'Vegetariano'] | ||
foods.forEach(food => { | ||
it(`Cadastro com a comida ${food}`, () => { | ||
cy.get('#formNome').type('Usuario') | ||
cy.get('#formSobrenome').type('Qualquer') | ||
cy.get(`[name=formSexo][value=F]`).click() | ||
cy.xpath(`//label[contains(., '${food}')]/preceding-sibling::input`).click() | ||
cy.get('#formEscolaridade').select('Doutorado') | ||
cy.get('#formEsportes').select('Corrida') | ||
cy.get('#formCadastrar').click() | ||
cy.get('#resultado > :nth-child(1)').should('contain', 'Cadastrado!') | ||
}) | ||
}) | ||
|
||
it('Deve selecionar todos usando o each', () => { | ||
cy.get('#formNome').type('Usuario') | ||
cy.get('#formSobrenome').type('Qualquer') | ||
cy.get(`[name=formSexo][value=F]`).click() | ||
|
||
cy.get('[name=formComidaFavorita]').each($el => { | ||
// $el.click() | ||
if ($el.val() !== 'vegetariano') | ||
cy.wrap($el).click() | ||
}) | ||
|
||
cy.get('#formEscolaridade').select('Doutorado') | ||
cy.get('#formEsportes').select('Corrida') | ||
cy.get('#formCadastrar').click() | ||
cy.get('#resultado > :nth-child(1)').should('contain', 'Cadastrado!') | ||
// cy.clickAlert('#formCadastrar', 'Tem certeza que voce eh vegetariano?') | ||
}) | ||
|
||
}) |
Oops, something went wrong.