-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: iFrame input focus should not cause blur if input already activeElement #8112
Conversation
Thanks for taking the time to open a PR!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did manually verify that this fixes the original issue. A test would be ideal...maybe someone else on the team has an idea on how to test this. @chrisbreiding @bkucera ?
I added a test. It's the repro one from the issue. Needed to try it out to make sure it would work. It did, so I figured I'd go ahead and commit it. |
@chrisbreiding This test would fail in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
K, I found a way to make this break in the tests without manually focusing out. This basically breaks if you open DevTools, so we can have the Devtools auto open to make this test fail.
This will only work in Chrome, I don't know how to open devtools in Electron from preferences. This bug doesn't happen in Firefox, so we won't need a test for that. I think this is better than nothing.
@chrisbreiding I'm not sure what the best way is to have these preferences apply for a single spec run in our driver tests.
module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, launchOptions) => {
if (browser.family === 'chromium' && browser.name !== 'electron') {
// auto open devtools
launchOptions.args.push('--auto-open-devtools-for-tabs')
}
return launchOptions
})
}
…wser being out of focus
I moved the test to be an e2e test so the open devtools could be applied to it. Don't think there's a way to do that individually for a driver test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this test also depends on the Chrome browser being headed so I added that to the e2e test. I checked that the e2e test fails without this fix and passes with it and added some clarifying comments. 👍
Groovy. Thanks for all your help everyone! 💪 |
.type()
are actually blurred (when Test Runner is not focused) #8111User facing changelog
Fixed an issue where focusing on an input inside iFrame contents causes blur if the input was already selected.
Additional details
Here's a quick rundown on what's wrong and how this PR seeks to fix it.
We are looking to start using Cypress to integration-test our credit card checkout experience at Chess.com. Our payment vendor is Adyen and the way it works, each credit card input field is an iFrame coming from Adyen's server. Here's a screenshot with each iFrame annotated with a pink background:
When you complete the expiration month field, Adyen auto-tabs you to the expiration year field. When you complete that, Adyen auto-tabs you to the security code. When auto-tabbing, Adyen also auto-focuses on the
<input>
within each iFrame.My integration test in part looks like this:
When
.type()
executes for each of these, this click event occurs:cypress/packages/driver/src/cy/commands/actions/type.js
Line 401 in 7da2c4d
...which triggers this:
cypress/packages/driver/src/cy/mouse.js
Line 530 in 7da2c4d
...which triggers this:
cypress/packages/driver/src/cy/mouse.js
Line 478 in 7da2c4d
...which triggers this:
cypress/packages/driver/src/cy/focused.js
Line 126 in 7da2c4d
In other words, this focusing on an input that's already focused results in it blurring, which is the bug. In this scenario, this conditional here is evaluating
true
where it should be evaluatingfalse
:cypress/packages/driver/src/cy/focused.js
Line 121 in 7da2c4d
That is because there's a hardcoded assumption here that the
document
in question is the topdocument
, not thedocument
that the element in question belongs to:cypress/packages/driver/src/cy/focused.js
Line 224 in 7da2c4d
By giving an optional argument to specify the
document
in thegetFocused
function, iFrames get better support in Cypress.How has the user experience changed?
n/a
PR Tasks