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

356
Views
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 answers
Answer question

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 Report

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 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!