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

Add support for {home} and {end} special character sequences #2033

Closed
kyleoliveiro opened this issue Jun 26, 2018 · 10 comments
Closed

Add support for {home} and {end} special character sequences #2033

kyleoliveiro opened this issue Jun 26, 2018 · 10 comments

Comments

@kyleoliveiro
Copy link

@kyleoliveiro kyleoliveiro commented Jun 26, 2018

Current behavior:

cy.type('{home}') and cy.type('{end}') are not supported:

CypressError: Special character sequence: '{home}' is not recognized. Available sequences are: {selectall}, {del}, {backspace}, {esc}, {{}, {enter}, {leftarrow}, {uparrow}, {rightarrow}, {downarrow}, {alt}, {option}, {ctrl}, {control}, {meta}, {command}, {cmd}, {shift}
CypressError: Special character sequence: '{end}' is not recognized. Available sequences are: {selectall}, {del}, {backspace}, {esc}, {{}, {enter}, {leftarrow}, {uparrow}, {rightarrow}, {downarrow}, {alt}, {option}, {ctrl}, {control}, {meta}, {command}, {cmd}, {shift}

Desired behavior:

Support the {home} and {end} special character sequences.

Versions

Cypress 3.0.1

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Jun 26, 2018

Great suggestion. The code for special characters can be found here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cypress/keyboard.coffee#L11

As a workaround, you should be able to create a custom command for these by triggerering the keyboard events after knowing the keyCode like this:

Cypress.Commands.add('homeKey', {prevSubject: 'element'} (subject, opts) => {
  cy.wrap(subject).trigger('keydown', {
      keyCode: 36,
      which: 36,
      shiftKey: shiftKey,
      ctrlKey: ctrlKey
  });

  return subject
});

Cypress.Commands.add('endKey', {prevSubject: 'element'} (subject, opts) => {
  cy.wrap(subject).trigger('keydown', {
      keyCode: 35,
      which: 35,
      shiftKey: opts.shiftKey,
      ctrlKey: opts.ctrlKey
  });

  return subject
});
@brian-mann
Copy link
Member

@brian-mann brian-mann commented Jun 26, 2018

That'll fire a single event but it won't move the cursor or perform the default action and we're missing stuff like keypress and keyup.

@kyleoliveiro
Copy link
Author

@kyleoliveiro kyleoliveiro commented Jun 27, 2018

Also consider adding support for {pgup} and {pgdown}.

@brian-mann
Copy link
Member

@brian-mann brian-mann commented Jan 9, 2019

@Bkucera can you comment on this issue since it's being addressed in your native events PR / keyboard enhancements. Tag it or mark as duplicate / explain what we're doing in the upcoming release, etc.

@Bkucera
Copy link
Member

@Bkucera Bkucera commented Jan 10, 2019

as @brian-mann mentioned, Native Events will allow all of these "special" keys including pageup, pagedown, home, end, etc. Using native events, two things are enabled:

  1. events fired (keydown for example) will be trusted (have property isTrusted:true and allow privledged apis such as document.execCommand('copy') in the event handlers)

  2. event can perform its default action (for example, pagedown would scroll the page`)

Currently, we only support a subset of these special keys because default actions are complex and sometimes impossible to fulfill without native events.

In the PR for adding {home} and {end} keys [#3071] the default action is fulfilled only for the case where the focused element is a text editable- using a non-standard browser API which is not in IE11. That being said I'm happy with that strategy if users rely on the default action of home/end in their tests.

@kyleoliveiro do you need the default action performed for home/end keys or are you using e.preventDefault() in your event handler?

@Ajith456

This comment was marked as off-topic.

@skorunka
Copy link

@skorunka skorunka commented Feb 15, 2019

This is a very usefull feature to add! Thanks.

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Mar 15, 2019

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

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented Mar 15, 2019

Released in 3.2.0.

@skorunka
Copy link

@skorunka skorunka commented Mar 24, 2019

Great job! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants