Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/cy/commands/actions/type.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand Down Expand Up @@ -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) ->
Expand Down
9 changes: 8 additions & 1 deletion packages/driver/src/cypress/error_messages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
Expand Down
4 changes: 2 additions & 2 deletions packages/driver/src/cypress/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const $Keyboard = {
type (options = {}) {
_.defaults(options, {
delay: 10,
disableSpecialCharSequences: false,
parseSpecialCharSequences: true,
onEvent () {},
onBeforeEvent () {},
onBeforeType () {},
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this PR but this would be a good place to introduce template tags using the common-tags module.


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()
})
Expand Down