diff --git a/cli/types/index.d.ts b/cli/types/index.d.ts index 7786c0c3a66..cde3e7d074d 100644 --- a/cli/types/index.d.ts +++ b/cli/types/index.d.ts @@ -2255,12 +2255,12 @@ declare namespace Cypress { */ delay: number /** - * Disable typing special characters for strings surrounded by `{}`, - * such as `{esc}`, and type the literal characters instead + * Parse special characters for strings surrounded by `{}`, + * such as `{esc}`. Set to `false` to type the literal characters instead * - * @default false + * @default true */ - disableSpecialCharSequences: boolean + parseSpecialCharSequences: boolean /** * Forces the action, disables waiting for actionability * diff --git a/packages/driver/src/cy/commands/actions/type.coffee b/packages/driver/src/cy/commands/actions/type.coffee index fb2ce3cf600..2cc680ef6da 100644 --- a/packages/driver/src/cy/commands/actions/type.coffee +++ b/packages/driver/src/cy/commands/actions/type.coffee @@ -32,7 +32,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> force: false delay: 10 release: true - disableSpecialCharSequences: false + parseSpecialCharSequences: true waitForAnimations: config("waitForAnimations") animationDistanceThreshold: config("animationDistanceThreshold") }) @@ -246,7 +246,7 @@ module.exports = (Commands, Cypress, cy, state, config) -> chars: options.chars delay: options.delay release: options.release - disableSpecialCharSequences: options.disableSpecialCharSequences + parseSpecialCharSequences: options.parseSpecialCharSequences window: win updateValue: (el, key) -> diff --git a/packages/driver/src/cypress/error_messages.coffee b/packages/driver/src/cypress/error_messages.coffee index 29ebd6bfb76..751de97eb10 100644 --- a/packages/driver/src/cypress/error_messages.coffee +++ b/packages/driver/src/cypress/error_messages.coffee @@ -903,7 +903,14 @@ module.exports = { type: empty_string: "#{cmd('type')} cannot accept an empty String. You need to actually type something." - invalid: "Special character sequence: '{{chars}}' is not recognized. Available sequences are: {{allChars}}" + readonly: "#{cmd('type')} cannot type into an element with a 'readonly' attribute. The element typed into was: {{node}}" + invalid: """ + Special character sequence: '{{chars}}' is not recognized. Available sequences are: {{allChars}} + + If you want to skip parsing special character sequences and type the text exactly as written, pass the option: {parseSpecialCharSequences: false} + + https://on.cypress.io/type + """ invalid_date: "Typing into a date input with #{cmd('type')} requires a valid date with the format 'yyyy-MM-dd'. You passed: {{chars}}" invalid_month: "Typing into a month input with #{cmd('type')} requires a valid month with the format 'yyyy-MM'. You passed: {{chars}}" invalid_week: "Typing into a week input with #{cmd('type')} requires a valid week with the format 'yyyy-Www', where W is the literal character 'W' and ww is the week number (00-53). You passed: {{chars}}" diff --git a/packages/driver/src/cypress/keyboard.js b/packages/driver/src/cypress/keyboard.js index 36ef6c46d62..e281470bfb4 100644 --- a/packages/driver/src/cypress/keyboard.js +++ b/packages/driver/src/cypress/keyboard.js @@ -338,7 +338,7 @@ const $Keyboard = { type (options = {}) { _.defaults(options, { delay: 10, - disableSpecialCharSequences: false, + parseSpecialCharSequences: true, onEvent () {}, onBeforeEvent () {}, onBeforeType () {}, @@ -352,7 +352,7 @@ const $Keyboard = { let keys = options.chars - if (!options.disableSpecialCharSequences) { + if (options.parseSpecialCharSequences) { keys = options.chars.split(charsBetweenCurlyBracesRe).map((chars) => { if (charsBetweenCurlyBracesRe.test(chars)) { //# allow special chars and modifiers to be case-insensitive diff --git a/packages/driver/test/cypress/integration/commands/actions/type_spec.js b/packages/driver/test/cypress/integration/commands/actions/type_spec.js index dd052b5a3d0..f30007e895c 100644 --- a/packages/driver/test/cypress/integration/commands/actions/type_spec.js +++ b/packages/driver/test/cypress/integration/commands/actions/type_spec.js @@ -1529,10 +1529,10 @@ describe('src/cy/commands/actions/type', () => { describe('specialChars', () => { - context('disableSpecialCharSequences: true', () => { + context('parseSpecialCharSequences: false', () => { it('types special character sequences literally', (done) => { cy.get(':text:first').invoke('val', 'foo') - .type('{{}{backspace}', { disableSpecialCharSequences: true }).then(($input) => { + .type('{{}{backspace}', { parseSpecialCharSequences: false }).then(($input) => { expect($input).to.have.value('foo{{}{backspace}') done() @@ -4340,7 +4340,11 @@ describe('src/cy/commands/actions/type', () => { const allChars = _.keys(Keyboard.specialChars).concat(_.keys(Keyboard.modifierChars)).join(', ') - expect(err.message).to.eq(`Special character sequence: '{bar}' is not recognized. Available sequences are: ${allChars}`) + expect(err.message).to.eq(`Special character sequence: '{bar}' is not recognized. Available sequences are: ${allChars} + +If you want to skip parsing special character sequences and type the text exactly as written, pass the option: {parseSpecialCharSequences: false} + +https://on.cypress.io/type`) done() })