No tienes acceso a esta clase

¡Continúa aprendiendo! Únete y comienza a potenciar tu carrera

Hooks

10/23
Recursos

Aportes 3

Preguntas 0

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

Hooks

📚 Documentación
Como lo indica la documentación de Cypress, los hooks son proveedores que permiten, mediante condicionales, realizar operaciones antes before / después after de un conjunto de pruebas o antes de beforeEach/ después afterEach prueba.
.
La versatilidad de su uso es, como bien lo indica el instructor, para encapsular bloques operativos como pipelines o flujos de trabajo.
.
Recordemos que Cypress es un framework que opera en diferentes capas, unitarias / integración E2E, que se puede complementar con librerías como Testing Library / Jest, por lo que dependiendo de su intención, podríamos atacar con mayor certeza casos de uso o requerimientos.

before(() => {
  // root-level hook
  // runs once before all tests
})

beforeEach(() => {
  // root-level hook
  // runs before every test block
})

afterEach(() => {
  // runs after each test block
})

after(() => {
  // runs once all tests are done
})

describe('Hooks', () => {
  before(() => {
    // runs once before all tests in the block
  })

  beforeEach(() => {
    // runs before each test in the block
  })

  afterEach(() => {
    // runs after each test in the block
  })

  after(() => {
    // runs once after all tests in the block
  })
})

Me genera el siguiente error en el 2do y 3er Assertion

/// <reference types="cypress" />

describe('Assertions', () => {
	before(() => {
		cy.visit('/automation-practice-form')
	})

	it('Assert 1', () => {
		// cy.visit('/automation-practice-form')
		cy.url().should('include', 'demoqa.com')
		cy.get('#firstName')
			.should('be.visible')
			.and('have.attr', 'placeholder', 'First Name')
	})

	it('Assert 2', () => {
		// cy.visit('/automation-practice-form')
		cy.url().should('include', 'demoqa.com')
		cy.get('#firstName').then((element) => {
			expect(element).to.be.visible
			expect(element).to.have.attr('placeholder', 'First Name')
		})
	})

	it('Assert 3', () => {
		// cy.visit('/automation-practice-form')
		cy.url().should('include', 'demoqa.com')
		cy.get('#firstName').then((element) => {
			assert(element.attr('placeholder', 'Firts Name'))
		})
	})
})

![](

Lo usé antes de comenzar el describe, dentro del describe y luego al salir del describe.