-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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(test): make sure selection is not empty before running copy command #4772
Conversation
test/evaluation.spec.js
Outdated
expect(result).toBe(true); | ||
await page.evaluate(() => document.body.appendChild(document.createTextNode('test'))); | ||
const selectResult = await page.evaluate(() => document.execCommand('selectAll')); | ||
expect(selectResult).toBe(true); |
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.
Firefox is unhappy about this. Yay! Browsers!
Let's just do this with window.getSelection to not mess around more with execCommand than we have to, or just don't assert that the selectAll worked.
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.
Updated expectations to check only result of 'copy'.
…py command is sufficient
test/evaluation.spec.js
Outdated
@@ -226,6 +226,8 @@ module.exports.addTests = function({testRunner, expect}) { | |||
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created'); | |||
}); | |||
it('should simulate a user gesture', async({page, server}) => { | |||
await page.evaluate(() => document.body.appendChild(document.createTextNode('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.
Nit: you can do these all in one evaluate, save some hops.
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.
Good point, done. Await and arrow functions make the code so much more readable that it's easy to forget that there are roundtrips over the protocol on each evaluate invocation :-)
…nd (puppeteer#4772) If current selection is empty document.execCommand('copy') may return false in some browsers (e.g. WebKit based ones).
If current selection is empty document.execCommand('copy') may return false in some browsers (e.g. WebKit based ones).