Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to ignore special character sequences for cy.type #4287

Closed
WiseBird opened this issue May 23, 2019 · 14 comments · Fixed by #4744 or #4761
Closed

Allow to ignore special character sequences for cy.type #4287

WiseBird opened this issue May 23, 2019 · 14 comments · Fixed by #4744 or #4761
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: enhancement Requested enhancement of existing feature

Comments

@WiseBird
Copy link

Current behavior:

cy.type considers everything in {} as modifier sequence. In our app we have embedded code runner. For testing we put there code from fixtures with cy.type. And cy.type throws CypressError: Special character sequence: '{...}' is not recognized when code includes some braced expression.

Desired behavior:

Add option to cy.type to not treat {} as modifier sequence.

Versions

Cypress: 3.2.0

@WiseBird WiseBird changed the title Allow to ignore modifier sequences for type Allow to ignore modifier sequences for cy.type May 23, 2019
@jennifer-shehane
Copy link
Member

jennifer-shehane commented May 23, 2019

@WiseBird You can type {{} to type the literal { key as shown in the docs, so this should work:

cy.get('input')
  .type('{{}mycommand}')
  .should('have.value', '{mycommand}')

Looks a little bit funky, but we had to choose some character, happened to be {

@WiseBird
Copy link
Author

@jennifer-shehane Yes, I can escape them. But as I said we type source code, it can be quite big. You need to go through it and find all lines with both { } and then escape. Replacing all { with {{ wont work as if there is no } cypress will type both characters.

Wouldn't it be much easier to simply say that there is no control sequences?

@jennifer-shehane
Copy link
Member

We could probably add an option to type like, 'charSequences: false`. This will be pretty low priority for our team to work on though, since it is possible to achieve what is needed for this to work.

We are always welcome to pull requests.

Code for .type(): https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/actions/type.coffee#L24
Tests for `.type(): https://github.com/cypress-io/cypress/blob/develop/packages/driver/test/cypress/integration/commands/actions/type_spec.coffee#L1143

@jennifer-shehane jennifer-shehane added type: enhancement Requested enhancement of existing feature pkg/driver This is due to an issue in the packages/driver directory good first issue Good for newcomers priority: low 🎗 labels May 24, 2019
@jennifer-shehane jennifer-shehane changed the title Allow to ignore modifier sequences for cy.type Allow to ignore special character sequences for cy.type May 24, 2019
@WiseBird
Copy link
Author

Sorry for my stupidity. While looking at tests I got how escaping really works.

@jennifer-shehane jennifer-shehane added type: question and removed good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory priority: low 🎗 type: enhancement Requested enhancement of existing feature labels May 28, 2019
@WORMSS
Copy link

WORMSS commented May 29, 2019

I don't know if it's possible to re-open this request? or if I should open a new issue?
having to do

cy.get(el).type(myMessage.replace(/{/g, '{{}')).type('{enter}');

much nicer to have

cy.get(el).type(myMessage, { commands: false }).type('{enter}');

I will admit it doesn't make the code anyshorter, but much easier to read the intent of the action.

Reason this has become an issue is because we are dealing a lot with inputting mustache type strings into inputs and there is always someone who forgets this and spends a while trying to work it out.

@jennifer-shehane
Copy link
Member

Another pretty reasonable argument for allowing an options argument to turn off special chars #4491

@jennifer-shehane jennifer-shehane added type: enhancement Requested enhancement of existing feature and removed type: question labels Jun 21, 2019
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jun 21, 2019
@jennifer-shehane jennifer-shehane added pkg/driver This is due to an issue in the packages/driver directory good first issue Good for newcomers and removed stage: ready for work The issue is reproducible and in scope labels Jun 21, 2019
@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Jul 17, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 18, 2019

The code for this is done in cypress-io/cypress#4744, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@brian-mann
Copy link
Member

We need to rename this option to be parseSpecialCharSequences: false to couple the option with the intended behavior in an affirmative way - as opposed to inverting it with disable*: true.

@brian-mann brian-mann reopened this Jul 18, 2019
@brian-mann
Copy link
Member

@cypress-io/test-runner someone feel free to open a new PR fixing this.

@kuceb
Copy link
Contributor

kuceb commented Jul 18, 2019

I suggest reverting this altogether, and you can simply have a function that escapes your string:

const rawTypeString = (str) => str.replace(/{/g, '{{}')
cy.type(rawTypeString('{hello}'))

As bonus, its even more readable, since I get told I'm passing a rawTypeString before I even know the string

@WORMSS
Copy link

WORMSS commented Jul 19, 2019

The whole point of this, is to remove the crappy str.replace.

@jennifer-shehane
Copy link
Member

We decided to provide an option to .type(), but rename is to parseSpecialCharacterSequences. This will be part of our next feature release. If you want to download the pre-release version to use this new feature there are instructions here: 50a285a#commitcomment-34434312

The code for this is done in #4761, but this has yet to be released. We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jul 29, 2019

Released in 3.4.1.

@RubenGarcia
Copy link

RubenGarcia commented Jan 29, 2021

Can you also add documentation? A search for "parseSpecialCharacterSequences cypress" in google only returns this page.
Edit: the option was renamed to parseSpecialCharSequences and is available at
https://docs.cypress.io/api/commands/type.html#Arguments

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Feb 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers pkg/driver This is due to an issue in the packages/driver directory type: enhancement Requested enhancement of existing feature
Projects
None yet
6 participants