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
Need tab support #299
Comments
I'd like to hear more about what you are looking to cover in terms of accessibility testing. Can you give me an example of a use case you are trying to test with the tab key? Right now there is not a way to press "tab". Currently we simulate all events in Cypress - although we automatically backfill in the browser's default behavior on all actions, which means that your application does what it does identically to native events. The problem with The solution for us is to enable native events within Cypress. We can "opt into" native events whenever we want, the problem is mostly with the UX experience around the debugger protocol. Namely that you cannot have Dev Tools open and issue native events due to the limitation of Chrome's debugger protocol. There is an open issue in Chromium to add multiplexing support so we've been waiting for that to go live. Until then we will kick the can, or eventually be forced into creating a good UX experience that either automatically closes Dev Tools, or prompts the user that their tests cannot continue until it is closed. |
thanks for the response The tab key is one of the primary ways a keyboard user moves around the page so it's difficult to write a high confidence accessibility test without it. In my case I'm building custom components that comply with the aria authoring practices guide. The first thing I would like to do on every page is press tab to focus the element. I can fake this by calling click() but it's not really the same. A non-sighted user will never use the mouse so calling click() feels a bit like cheating and you could imagine a situation where an element has one behavior when clicked and a different behavior when focused via the tab key. |
If you're testing the behavior of an element coming into focus, or you're testing things like styles you can just focus the element directly. cy.get("input").focus() What this doesn't test for is what the browser's behavior when clicking "tab". But you can often indirectly test this. For instance, you could just make sure that the element it's supposed to focus on has |
Yeah that's what I've been doing. Still, I would prefer |
I have a different use case for This is obviously distinct from accessibility use cases (as described above). Any update on |
In Chrome 63, there is support for multiplexing and we can now better handle native events. See #311 |
@jennifer-shehane Is this on the road map to be implemented? Or should we not expect this any time soon? |
I'd love to know as well. Just ran into this issue while writing a form validation test. |
Me too . I was expecting some way to tab to the next field like .type({tab}) |
Same as the above. I'm testing an app that mimics desktop application and heavily relies on keyboard usage. |
Has anyone found a good workaround for this? It seems as if we're not getting a tab function.. |
This seems to work: Cypress.Commands.add('typeTab', (shiftKey, ctrlKey) => {
cy.focused().then(($el) => {
cy.wrap($el).trigger('keydown', {
keyCode: 9,
which: 9,
shiftKey: shiftKey,
ctrlKey: ctrlKey
});
});
}); |
@scottschafer that fires the event, but the browser will not perform the default action such as moving the tab focus to the next focusable element |
@scottschafer This should be able to be simplified to this: Cypress.Commands.add('typeTab', (shiftKey, ctrlKey) => {
cy.focused().trigger('keydown', {
keyCode: 9,
which: 9,
shiftKey: shiftKey,
ctrlKey: ctrlKey
});
}); |
@brian-mann , ah. In our web app we specifically handle keyboard events and change focus programmatically. It works for us - sorry this won't work for you. |
@scottschafer Yes, glad to see you got this work in your use case. It should help anyone else that programmatically works off of the user's specific |
Whaaat? Tabbing was literally the first thing I tried testing
Wouldn't it be possible to allow users to customize the "algorithm" for tabbing? Figuring out where the focus will go is indeed a tricky problem, but for a majority of usecases it should work pretty straightforward. Figure out what is the next focusable element in the DOM after the current There are a few very good libs which also try to figure out which elements are focusable in order to trap focus in a modal or a dropdown. Maybe it's a good starting point to figure out what kind of algorithm they use to intercept focus leaving the modal and taking it back to the first focusable element in it? |
I think the key is to find or come up with an implementation that works for your use case. It's hard to come up with a general solution. FWIW, here's my implementation roughly based off of some of jQuery UI's logic: https://github.com/getstreamline/menu/blob/master/cypress/support/index.js#L39 One of the gotchas is that the It's naive but works for my use case! |
@decafdennis your tabbing stuff works well for me, thanks! The solution @jennifer-shehane posted wasn't working with the "shiftKey" variable for some reason. Tabbed forward but not backward. |
This comment has been minimized.
This comment has been minimized.
Here's one example I've encountered, that being that |
I am really thinking that keyboard and mouse events does not trigger well with cypress. |
+1 for tab key, it's a basic part of accessible navigation. |
agreed - essential for accessible navigation testing |
+1 it's an essential feature of accessibility tests. |
+1 |
This issue has been open for quite some years and a lot of people follow it (and thus get emails for new comments). Please refrain from posting comments that merely say “+1” and clutter the issue. These make it more difficult for people to find other comments that discuss what is needed to move this forward or other packages that people can use as a workaround. Instead of posting “+1” please hit the |
+1 |
1 similar comment
+1 |
Just unsubscribe from the thread. It's not fixed in 6 years. The chance for a better project/stack popping up is higher than cypress getting its shit together :) |
This needs to be prioritised in some manner. Leaving disabled people behind as we all forge ahead only testing mouse interactions is probably a violation of policy for many if not law. |
https://github.com/microsoft/playwright is already here and supports any keys |
What is the threshold for getting this in? Literally has more thumbs up than people watching this repo |
This likely isn't getting implemented. Some decisions made at a fundamental level put it in the "too hard" basket. Thus as mentioned above, the real solution is everyone switching to new tooling which doesn't suffer the same design flaw. |
Sad that it is taking years to get recognition that USERS use the tab key to navigate web pages. Sad. |
Just use |
Description
As mentioned here https://docs.cypress.io/v1.0/docs/type#section-typing-tab-key-does-not-work. For accessibility testing I need to be able to tell the keyboard to press tab. If
cy.tab
is not currently supported is there some way to work around this?The text was updated successfully, but these errors were encountered: