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 · 9 comments

Comments

6 participants
@kyleoliveiro
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

kyleoliveiro commented Jun 27, 2018

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

@brian-mann

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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.

Copy link

Ajith456 commented Feb 6, 2019

Hi Jennifer-Shehane, I'm new for Cypress.io and I'm not able to write test case for check the length of password please help me. and i need sample projects also and i waiting for your replay.

thank u

@skorunka

This comment has been minimized.

Copy link

skorunka commented Feb 15, 2019

This is a very usefull feature to add! Thanks.

@jennifer-shehane

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

cypress-bot bot commented Mar 15, 2019

Released in 3.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.