Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
Which would be the best choice when having to reuse selectors in Cypress?

I know Cypress team encourage to use actions instead of page objects, so which would be the best choice when having to reuse an element?

I don't want to be updating a selector in many places so I went for this option:

Cypress.Commands.add('getStartDateInput',() => cy.get('input[t-selector="startDate"]');

So If I have to interact with this element in some other places I will just call this new action. Even though this is leading me to have many new 'mini' actions like this in my commands file just in order to not have to update selectors in many places.

Am I doing it right? Any other suggestion?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I use a very simple javascript way to manage and reuse my locators. You can use this too if it works with your use case.

Step 1: Create a pageObject folder(I created it inside the integration folder) and inside that create a js file. Let's name this as selectors.js. Inside the selectors.js file, write all your selectors like this:

export default {
    toDoBtn: 'button[type="submit"]',
    starteDate: 'input[t-selector="startDate"]',
    input: 'form > input',
    listItems: 'ul > li'
};

Step 2: Now import this file into your spec file using the import command.

import selectors from './pageObject/selectors.js';

And then in your test you can use:

cy.get(selectors.starteDate).should('be.visible')
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda