DEV Community

loading...
Cover image for How to HIGHLIGHT text with Cypress

How to HIGHLIGHT text with Cypress

Christine Zierold
Proven ISTQB agile certified testing expert, with 10+ years of automation engineering experience, designing, maintaining, and expanding automated tests.
・1 min read

I recently wrote automated UI tests for a text editor application. One of the most important functions was to format text in different ways (e.g. text styles or text alignments). My biggest issue was to figure out how to highlight🖍️ text with Cypress in order to change the formatting of that text.

This feature is an open Github issue in the Cypress repository. I tried out several of their solutions and this is the one which worked best for me:

// Highlight text in the sectionArea
cy.get(sectionArea).realPress( "Shift","ArrowLeft","ArrowLeft");
Enter fullscreen mode Exit fullscreen mode

I used the command realPress() from Cypress real events to simulate the highlighting of text via the keyboard⌨️. This was the easiest solution as I have already used other commands from Cypress real events to solve other issues.

Discussion (0)