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

172
Views
¿Es posible crear pruebas dinámicas en Cypress con funciones que contengan comandos de Cypress?

Estoy tratando de crear múltiples pruebas basadas en la cantidad de funciones en una matriz que paso, para poder tener un bloque de describe y crear pruebas a medida que crece nuestro proyecto.

He encontrado varios ejemplos ( aquí , ejemplos de aplicaciones del mundo real ), pero todos estos ejemplos crean una matriz simple sin invocar ningún comando de Cypress. Necesito pasar una serie de funciones que invocan comandos de Cypress ( NO Comandos personalizados) como cy.get()

Lo que me gustaría trabajar:

 //loginPageController.js export default class LoginPageController { thingOne() { cy.get('some things') expect(some assertion) } thingTwo() { cy.get('some other things') expect(another assertion) } getAllThings() { return [this.thingOne(), this.thingTwo()] } }
 //login.spec.js import LoginPageController from '../../support/Controllers/loginPageController' const lPC = new LoginPageController describe('Login Tests', function() { beforeEach(function() { cy.visit('myapp') }) lPC.getAllThings().forEach(function() { it('tries each scenario', function() { // do stuff }) })

Mensaje de error

 The following error originated from your test code, not from Cypress. > Cannot call cy.get() outside a running test. This usually happens when you accidentally write commands outside an it(...) test.

lo que he probado

  1. it.forEach(getAllTheThings)('it should do the things', function(){})
  2. Establecer la función como una variable en un bloque before const lPC.getAllThings() = allThings que en realidad solo ejecuta la función con éxito en el before
  3. Aliasing/wrapping como cy.wrap(lPC.getAllThings()).as('allTheThings) (que probablemente no sea válido, pero en este momento solo estoy haciendo cambios)
  4. El uso de un archivo de fixture pero .js no parece ser compatible actualmente y pasaré una serie de funciones, no un simple objeto JSON.

Solo trato de mantener las cosas SECAS y solo escribo una describe que arroja tantas pruebas como funciones incluyo en ese lPC.getAllThings()

about 4 years ago · Juan Pablo Isaza
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!