Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select text using cypress [cypress]

I'm looking to test a text editor like https://github.com/brijeshb42/medium-draft using Cypress. But I can't find a way to select text using it. Does anyone have a clue on how to do that?

I'd have to select a specific text range in order for the test to be effective.

like image 366
yamadapc Avatar asked Apr 24 '18 19:04

yamadapc


People also ask

How do you fetch text in Cypress?

Cypress can validate the text on an element with the help of jQuery text() method. This method shall help us to fetch the text content on the selected element. We can also put assertions on the text content of the element. cy.

How do you select data in Cypress?

Browser Automation with Cypress and Gherkin 2022The command select is used to work with static dropdown. In the html code, a dropdown has a select tag and the dropdown elements are represented by option tagname.

How do you select elements in Cypress?

To select an element by class you need to use . prefix and to select an element by its it, you should prefix id with # . The most common attribute you might find on your page would be a placeholder for an input or even a test-id where your selector starts and ends with square brackets.


1 Answers

The commented answer above was the clue I needed, but it needs a couple tweaks (at least as of the version I'm using: v3.1.5). The link has all the info, but the answer should be as follows

cy.type('{selectall}')

Note that it's ".type()" instead of ".text()" and the escape sequence is quoted...

like image 197
Mike Avatar answered Oct 10 '22 13:10

Mike