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

361
Vistas
How to select text and then perform a cypress test on it?

I have a small application to test on cypress. It has a editor for user to add description and stuff. The user can make the text bold, italic etc. The user can also remove the formatting added so far on the text. But to remove the formatting the text should be selected like we normally do in any word editor.

My question is how can I test this feature while keeping the text selected.

A simple code example would be as follows:

<p>This is the description text</p>

So far I have got this but this does not keep the text selected of course, any idea how to cater this?

            cy.get('p').contains('This is the description text');
            cy.get('.remove-formats').click();
            cy.get('.tools')
             .within(() => cy.get('button').should('not.have.class', 'is-active')); 
         

What change should I make in the first line that the text stays selected when the second line executes as I want the remove formats to be performed on the text only. Any help would be appreciated.

Edit:

The text editor is very simple just like the one we have for stackoverflow. enter image description here

Similar to how we need to select the text first and then click bold to get the text bold, otherwise it does not imply to the text. How would I structure cypress tests for this? I have selected the text through dblclick() but as soon as I click on any option to test that feature the text does not stay selected in cypress tests.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can use double click to select the text.

cy.contains('This is the description text').dblclick()

You can also use a combination of ctrl+A

cy.contains('This is the description text').click().type('{ctrl+a}')
about 4 years ago · Santiago Trujillo Denunciar

0

Try to use

 .type("{selectall}{leftarrow}")

from cypress docs {selectall} - Selects all text by creating a selection range

about 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