Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

386
Views
cy.get() no pudo encontrar un alias registrado cuando se usa antes del gancho
describe("Share Link", () => { beforeEach(() => { cy.generateLink().then(response => { let url = response.meeting_shared_link.split("/"); cy.wrap(url[url.length - 1]).as("link"); }); describe("when I turn on link sharing", () => { // This works. Changing it to a before hook breaks it. beforeEach(() => { cy.get("@link").then(link => cy.toggleLinkSharing({ link: link }) ); }); });

Actualmente estoy generando un alias - @link - en mi primer beforeEach , y luego accedo a él en el siguiente enlace beforeEach que está anidado en una descripción.

Mi problema es que necesito que el último enlace sea un before , en lugar de un beforeEach .

Cuando lo modifico a un enlace anterior, no puede encontrar el alias "enlace". ¿Por qué?

Entiendo que los alias se borran entre cada prueba, de ahí la necesidad del primer anzuelo beforeEach , pero ¿por qué no está disponible dentro de un anzuelo before ?

Editar: . Creo que puede deberse a que el último definido before de que el gancho se beforeEach antes que el primero antes de cada uno, en cuyo caso, el alias aún no existía. Si este es el caso, no es intuitivo. El anzuelo anterior solo debe activarse después de antes de Cada uno, ya que está anidado en otra descripción.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede cambiar el beforeEach() externo a before() y conservar el alias entre las pruebas con beforeEach(function() { cy.wrap(this.link).as('link') })

Funciona porque this.link no se borra entre pruebas, aunque se borre el alias @link .

 describe("Share Link", () => { before(() => { cy.wrap('my-url').as("link"); console.log('Outer before') }); describe("when I turn on link sharing", () => { beforeEach(function() { cy.wrap(this.link).as('link') }) // preserve the alias before(() => { cy.get("@link").then(link => { console.log('Inner before', link) }) }) it('1st test', () => { cy.get('@link').then(link => console.log('1st test', link)) }) it('2nd test', () => { cy.get('@link').then(link => console.log('2nd test', link)) }) }) })

Salida de consola

 Outer beforeEach Inner before my-url 1st test my-url 2nd test my-url
about 4 years ago · Juan Pablo Isaza Report

0

Puedes usar this.link y probar.

 describe("Share Link", () => { beforeEach(() => { cy.generateLink().then(response => { let url = response.meeting_shared_link.split("/"); cy.wrap(url[url.length - 1]).as("link"); }); describe("when I turn on link sharing", () => { // This works. Changing it to a before hook breaks it. beforeEach(() => { cy.toggleLinkSharing(this.link) }); });

Referencia aquí: https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Sharing-Context

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!