Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

362
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda