From fbe0525473f4afff882904b37955cf8ab3e2dd4b Mon Sep 17 00:00:00 2001 From: Wagner Aquino Date: Fri, 22 Sep 2023 08:19:55 -0500 Subject: [PATCH] =?UTF-8?q?Atualizando=20para=20nova=20vers=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cypress/e2e/0-curso/alert.cy.js | 81 +++++++++++++++++++++++ cypress/e2e/0-curso/arrow.cy.js | 35 ++++++++++ cypress/e2e/0-curso/asserts.cy.js | 85 ++++++++++++++++++++++++ cypress/e2e/0-curso/basic.cy.js | 44 +++++++++++++ cypress/e2e/0-curso/describe.cy.js | 24 +++++++ cypress/e2e/0-curso/dinamic.cy.js | 40 ++++++++++++ cypress/e2e/0-curso/elements.cy.js | 101 +++++++++++++++++++++++++++++ cypress/e2e/0-curso/fixture.cy.js | 18 +++++ cypress/e2e/0-curso/helpers.cy.js | 58 +++++++++++++++++ cypress/e2e/0-curso/iframe.cy.js | 23 +++++++ cypress/e2e/0-curso/locators.cy.js | 25 +++++++ cypress/e2e/0-curso/popup.cy.js | 48 ++++++++++++++ cypress/e2e/0-curso/promises.cy.js | 18 +++++ cypress/e2e/0-curso/sync.cy.js | 72 ++++++++++++++++++++ cypress/e2e/0-curso/time.cy.js | 53 +++++++++++++++ 15 files changed, 725 insertions(+) create mode 100644 cypress/e2e/0-curso/alert.cy.js create mode 100644 cypress/e2e/0-curso/arrow.cy.js create mode 100644 cypress/e2e/0-curso/asserts.cy.js create mode 100644 cypress/e2e/0-curso/basic.cy.js create mode 100644 cypress/e2e/0-curso/describe.cy.js create mode 100644 cypress/e2e/0-curso/dinamic.cy.js create mode 100644 cypress/e2e/0-curso/elements.cy.js create mode 100644 cypress/e2e/0-curso/fixture.cy.js create mode 100644 cypress/e2e/0-curso/helpers.cy.js create mode 100644 cypress/e2e/0-curso/iframe.cy.js create mode 100644 cypress/e2e/0-curso/locators.cy.js create mode 100644 cypress/e2e/0-curso/popup.cy.js create mode 100644 cypress/e2e/0-curso/promises.cy.js create mode 100644 cypress/e2e/0-curso/sync.cy.js create mode 100644 cypress/e2e/0-curso/time.cy.js diff --git a/cypress/e2e/0-curso/alert.cy.js b/cypress/e2e/0-curso/alert.cy.js new file mode 100644 index 0000000..ec2008f --- /dev/null +++ b/cypress/e2e/0-curso/alert.cy.js @@ -0,0 +1,81 @@ +/// + +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!') + }) +}) diff --git a/cypress/e2e/0-curso/arrow.cy.js b/cypress/e2e/0-curso/arrow.cy.js new file mode 100644 index 0000000..0bc02f3 --- /dev/null +++ b/cypress/e2e/0-curso/arrow.cy.js @@ -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) +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/asserts.cy.js b/cypress/e2e/0-curso/asserts.cy.js new file mode 100644 index 0000000..d324cb3 --- /dev/null +++ b/cypress/e2e/0-curso/asserts.cy.js @@ -0,0 +1,85 @@ +/// + +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) +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/basic.cy.js b/cypress/e2e/0-curso/basic.cy.js new file mode 100644 index 0000000..c435f0e --- /dev/null +++ b/cypress/e2e/0-curso/basic.cy.js @@ -0,0 +1,44 @@ +/// + +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!') + }) +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/describe.cy.js b/cypress/e2e/0-curso/describe.cy.js new file mode 100644 index 0000000..e9942ac --- /dev/null +++ b/cypress/e2e/0-curso/describe.cy.js @@ -0,0 +1,24 @@ +/// + +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...', () => { + + }) +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/dinamic.cy.js b/cypress/e2e/0-curso/dinamic.cy.js new file mode 100644 index 0000000..b9bd09b --- /dev/null +++ b/cypress/e2e/0-curso/dinamic.cy.js @@ -0,0 +1,40 @@ +/// + +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?') + }) + +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/elements.cy.js b/cypress/e2e/0-curso/elements.cy.js new file mode 100644 index 0000000..8caf4e4 --- /dev/null +++ b/cypress/e2e/0-curso/elements.cy.js @@ -0,0 +1,101 @@ +/// + +describe('Work with basic elements', () => { + beforeEach(() => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + }) + + it('Text', () => { + cy.get('body').should('contain', 'Cuidado') + // cy.get('body').should('have.text', 'Cuidado') + cy.get('span').should('contain', 'Cuidado') + // cy.get('div').should('contain', 'Cuidado') + cy.get('.facilAchar').should('contain', 'Cuidado') + cy.get('.facilAchar').should('have.text', 'Cuidado onde clica, muitas armadilhas...') + }) + + it('Links', () => { + cy.get('a:first-of-type').click() + cy.get('#resultado').should('have.text', 'Voltou!') + + cy.reload() + cy.get('#resultado').should('have.not.text', 'Voltou!') + cy.contains('Voltar').click() + cy.get('#resultado').should('have.text', 'Voltou!') + }) + + it('TextFields', () => { + cy.get('#formNome').type('Cypress Test') + cy.get('#formNome').should('have.value', 'Cypress Test') + + cy.get('#elementosForm\\:sugestoes') + .type('textarea') + .should('have.value', 'textarea') + + cy.get('#tabelaUsuarios > :nth-child(2) > :nth-child(1) > :nth-child(6) > input') + .type('???') + + cy.get('[data-cy=dataSobrenome]') + .type('Teste12345{backspace}{backspace}') + .should('have.value', 'Teste123') + + cy.get('#elementosForm\\:sugestoes') + .clear() + .type('Erro{selectall}acerto', { delay: 100 }) + .should('have.value', 'acerto') + }) + + it('RadioButton', () => { + cy.get('#formSexoFem') + .click() + .should('be.checked') + + cy.get('#formSexoMasc').should('not.be.checked') + + cy.get("[name=formSexo]").should('have.length', 2) + }) + + it('Checkbox', () => { + cy.get('#formComidaPizza') + .click() + .should('be.checked') + + cy.get('[name=formComidaFavorita]').click({ multiple: true }) + cy.get('#formComidaPizza').should('not.be.checked') + cy.get('#formComidaVegetariana').should('be.checked') + }) + + it('Combo', () => { + cy.get('[data-test=dataEscolaridade]') + .select('2o grau completo') + .should('have.value', '2graucomp') + + cy.get('[data-test=dataEscolaridade]') + .select('1graucomp') + .should('have.value', '1graucomp') + + cy.get('[data-test=dataEscolaridade] option') + .should('have.length', 8) + cy.get('[data-test=dataEscolaridade] option').then($arr => { + const values = [] + $arr.each(function () { + values.push(this.innerHTML) + }) + expect(values).to.include.members(["Superior", "Mestrado"]) + }) + }) + + it('Combo multiplo', () => { + cy.get('[data-testid=dataEsportes]') + .select(['natacao', 'Corrida', 'nada']) + // cy.get('[data-testid=dataEsportes]').should('have.value', ['natacao', 'Corrida', 'nada']) + cy.get('[data-testid=dataEsportes]').then($el => { + expect($el.val()).to.be.deep.equal(['natacao', 'Corrida', 'nada']) + expect($el.val()).to.have.length(3) + }) + + cy.get('[data-testid=dataEsportes]') + .invoke('val') + .should('eql', ['natacao', 'Corrida', 'nada']) + }) +}) diff --git a/cypress/e2e/0-curso/fixture.cy.js b/cypress/e2e/0-curso/fixture.cy.js new file mode 100644 index 0000000..f8dc440 --- /dev/null +++ b/cypress/e2e/0-curso/fixture.cy.js @@ -0,0 +1,18 @@ +/// + +describe('Fixtures tests', () => { + it('Get data form fixture file', function () { + cy.visit('https://wcaquino.me/cypress/componentes.html') + cy.fixture('userData').as('usuario').then(() => { + cy.get('#formNome').type(this.usuario.nome) + cy.get('#formSobrenome').type(this.usuario.sobrenome) + cy.get(`[name=formSexo][value=${this.usuario.sexo}]`).click() + cy.get(`[name=formComidaFavorita][value=${this.usuario.comida}]`).click() + cy.get('#formEscolaridade').select(this.usuario.escolaridade) + cy.get('#formEsportes').select(this.usuario.esportes) + }) + cy.get('#formCadastrar').click() + cy.get('#resultado > :nth-child(1)').should('contain', 'Cadastrado!') + }) +}) + diff --git a/cypress/e2e/0-curso/helpers.cy.js b/cypress/e2e/0-curso/helpers.cy.js new file mode 100644 index 0000000..97924a1 --- /dev/null +++ b/cypress/e2e/0-curso/helpers.cy.js @@ -0,0 +1,58 @@ +/// + +describe('Helpers...', () => { + it('Wrap', () => { + const obj = { nome: 'User', idade: 20 } + expect(obj).to.have.property('nome') + cy.wrap(obj).should('have.property', 'nome') + + cy.visit('https://wcaquino.me/cypress/componentes.html') + // cy.get('#formNome').then($el => { + // // $el.val('funciona via jquery') + // cy.wrap($el).type('funciona via cypress') + // }) + + const promise = new Promise((resolve, reject) => { + setTimeout(() => { + resolve(10) + }, 500) + }) + + cy.get('#buttonSimple').then(() => console.log('Encontrei o primeiro botao')) + // promise.then(num => console.log(num)) + cy.wrap(promise).then(ret => console.log(ret)) + cy.get('#buttonList').then(() => console.log('Encontrei o segundo botao')) + + cy.wrap(1).should(num => { + return 2 + }).should('be.equal', 1) + }) + + it('Its...', () => { + const obj = { nome: 'User', idade: 20 } + cy.wrap(obj).should('have.property', 'nome', 'User') + cy.wrap(obj).its('nome').should('be.equal', 'User') + + const obj2 = { nome: 'User', idade: 20, endereco: { rua: 'dos bobos' } } + cy.wrap(obj2).its('endereco').should('have.property', 'rua') + cy.wrap(obj2).its('endereco').its('rua').should('contain', 'bobos') + cy.wrap(obj2).its('endereco.rua').should('contain', 'bobos') + + cy.visit('https://wcaquino.me/cypress/componentes.html') + cy.title().its('length').should('be.equal', 20) + }) + + it('Invoke...', () => { + const getValue = () => 1; + const soma = (a, b) => a + b; + + cy.wrap({ fn: getValue }).invoke('fn').should('be.equal', 1) + cy.wrap({ fn: soma }).invoke('fn', 2, 5).should('be.equal', 7) + + cy.visit('https://wcaquino.me/cypress/componentes.html') + cy.get('#formNome').invoke('val', 'Texto via invoke') + cy.window().invoke('alert', 'Dá pra ver?') + cy.get('#resultado') + .invoke('html', '') + }) +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/iframe.cy.js b/cypress/e2e/0-curso/iframe.cy.js new file mode 100644 index 0000000..a1897c4 --- /dev/null +++ b/cypress/e2e/0-curso/iframe.cy.js @@ -0,0 +1,23 @@ +/// + +describe('Work with iFrames', () => { + it('Deve preencher campo de texto', () => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + cy.get('#frame1').then(iframe => { + const body = iframe.contents().find('body') + cy.wrap(body).find('#tfield') + .type('funciona?') + .should('have.value', 'funciona?') + }) + + }) + + it('Deve testar frame diretamente', () => { + cy.visit('https://wcaquino.me/cypress/frame.html') + cy.get('#otherButton').click() + cy.on('window:alert', msg => { + expect(msg).to.be.equal('Click OK!') + }) + }) +}) + diff --git a/cypress/e2e/0-curso/locators.cy.js b/cypress/e2e/0-curso/locators.cy.js new file mode 100644 index 0000000..946687c --- /dev/null +++ b/cypress/e2e/0-curso/locators.cy.js @@ -0,0 +1,25 @@ +/// + +describe('Work with basic elements', () => { + beforeEach(() => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + }) + + beforeEach(() => { + cy.reload() + }) + + it('using jquery selector', () => { + cy.get(':nth-child(1) > :nth-child(3) > [type="button"]') + cy.get('table#tabelaUsuarios tbody > tr:eq(0) td:nth-child(3) > input') + cy.get("[onclick*='Francisco']") + cy.get('#tabelaUsuarios td:contains(\'Doutorado\'):eq(0) ~ td:eq(3) > input') + cy.get('#tabelaUsuarios tr:contains(\'Doutorado\'):eq(0) td:eq(6) input') + }) + + it('using xpath', () => { + cy.xpath('//input[contains(@onclick, \'Francisco\')]') + cy.xpath("//table[@id='tabelaUsuarios']//td[contains(., 'Francisco')]/..//input[@type='text']") + cy.xpath("//td[contains(., 'Usuario A')]/following-sibling::td[contains(., 'Mestrado')]/..//input[@type='text']").type('funciona') + }) +}) \ No newline at end of file diff --git a/cypress/e2e/0-curso/popup.cy.js b/cypress/e2e/0-curso/popup.cy.js new file mode 100644 index 0000000..fdfa6bd --- /dev/null +++ b/cypress/e2e/0-curso/popup.cy.js @@ -0,0 +1,48 @@ +/// + +describe('Work with Popup', () => { + it('Deve testar popup diretamente', () => { + cy.visit('https://wcaquino.me/cypress/frame.html') + cy.get('#otherButton').click() + cy.on('window:alert', msg => { + expect(msg).to.be.equal('Click OK!') + }) + }) + + it('Deve verificar se o popup foi invocado', () => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + cy.window().then(win => { + cy.stub(win, 'open').as('winOpen') + }) + cy.get('#buttonPopUp').click() + cy.get('@winOpen').should('be.called') + }) + + describe('With links...', () => { + beforeEach(() => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + }) + + it('Check popup url', () => { + cy.contains('Popup2') + .should('have.prop', 'href') + .and('equal', 'https://wcaquino.me/cypress/frame.html') + }) + + it('Should access popup dinamically', () => { + cy.contains('Popup2').then($a => { + const href = $a.prop('href') + cy.visit(href) + cy.get('#tfield').type('funciona') + }) + }) + + it('Should force link on same page', () => { + cy.contains('Popup2') + .invoke('removeAttr', 'target') + .click() + cy.get('#tfield').type('funciona') + }) + }) +}) + diff --git a/cypress/e2e/0-curso/promises.cy.js b/cypress/e2e/0-curso/promises.cy.js new file mode 100644 index 0000000..ee75de6 --- /dev/null +++ b/cypress/e2e/0-curso/promises.cy.js @@ -0,0 +1,18 @@ +it('sem testes, ainda', () => { }) + +const getSomething = () => { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve(13); + }, 1000) + }) +} + +const system = async () => { + console.log('init'); + const some = await getSomething() + console.log(`Something is ${some}`) + console.log('end') +} + +system(); \ No newline at end of file diff --git a/cypress/e2e/0-curso/sync.cy.js b/cypress/e2e/0-curso/sync.cy.js new file mode 100644 index 0000000..e290fbd --- /dev/null +++ b/cypress/e2e/0-curso/sync.cy.js @@ -0,0 +1,72 @@ +/// + +describe('Esperas...', () => { + beforeEach(() => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + }) + + it('Deve aguardar elemento estar disponivel', () => { + cy.get('#novoCampo').should('not.exist') + cy.get('#buttonDelay').click() + cy.get('#novoCampo').should('not.exist') + cy.get('#novoCampo').should('exist') + cy.get('#novoCampo').type('funciona') + }) + + it('Deve fazer retrys', () => { + cy.get('#novoCampo').should('not.exist') + cy.get('#buttonDelay').click() + cy.get('#novoCampo').should('not.exist') + cy.get('#novoCampo') + // .should('not.exist') + .should('exist') + .type('funciona') + + }) + + it('Uso do find', () => { + cy.get('#buttonListDOM').click() + cy.get('#lista li') + .find('span') + .should('contain', 'Item 1') + // cy.get('#lista li') + // .find('span') + // .should('contain', 'Item 2') + cy.get('#lista li span') + .should('contain', 'Item 2') + + }) + + it('Uso do timeout', () => { + // cy.get('#buttonDelay').click() + // cy.get('#novoCampo', { timeout: 1000 }).should('exist') + + // cy.get('#buttonListDOM').click() + // // cy.wait(5000) + // cy.get('#lista li span', { timeout: 30000 }) + // .should('contain', 'Item 2') + + cy.get('#buttonListDOM').click() + cy.get('#lista li span') + .should('have.length', 1) + cy.get('#lista li span') + .should('have.length', 2) + }) + + it('Click retry', () => { + cy.get('#buttonCount') + .click() + .click() + .should('have.value', '111') + }) + + it('Should vs Then', () => { + cy.get('#buttonListDOM').then($el => { + // .should('have.length', 1) + // console.log($el) + expect($el).to.have.length(1) + cy.get('#buttonList') + }) + }) + +}) diff --git a/cypress/e2e/0-curso/time.cy.js b/cypress/e2e/0-curso/time.cy.js new file mode 100644 index 0000000..2403868 --- /dev/null +++ b/cypress/e2e/0-curso/time.cy.js @@ -0,0 +1,53 @@ +/// + +describe('Work with time', () => { + beforeEach(() => { + cy.visit('https://wcaquino.me/cypress/componentes.html') + }) + + it('Going back to the past', () => { + // cy.get('#buttonNow').click() + // cy.get('#resultado > span').should('contain', '07/11/2019') + + // cy.clock() + // cy.get('#buttonNow').click() + // cy.get('#resultado > span').should('contain', '31/12/1969') + + const dt = new Date(2012, 3, 10, 15, 23, 50) + cy.clock(dt.getTime()) + cy.get('#buttonNow').click() + cy.get('#resultado > span').should('contain', '10/04/2012') + }) + + it('Goes to the future', () => { + cy.get('#buttonTimePassed').click() + cy.get('#resultado > span').should('contain', '1695') + cy.get('#resultado > span').invoke('text').then(t => { + const number = parseInt(t) + cy.wrap(number).should('gt', 1587933052610) + }) + + cy.clock() + cy.get('#buttonTimePassed').click() + cy.get('#resultado > span').invoke('text').then(t => { + const number = parseInt(t) + cy.wrap(number).should('lte', 0) + }) + // cy.wait(1000) + // cy.get('#buttonTimePassed').click() + // cy.get('#resultado > span').invoke('text').should('lte', 1000) + + cy.tick(5000) + cy.get('#buttonTimePassed').click() + cy.get('#resultado > span').invoke('text').then(t => { + const number = parseInt(t) + cy.wrap(number).should('gte', 5000) + }) + cy.tick(10000) + cy.get('#buttonTimePassed').click() + cy.get('#resultado > span').invoke('text').then(t => { + const number = parseInt(t) + cy.wrap(number).should('gte', 15000) + }) + }) +}) \ No newline at end of file