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

fix(test): make sure selection is not empty before running copy command #4772

Merged
merged 3 commits into from Jul 30, 2019

Conversation

yury-s
Copy link
Contributor

@yury-s yury-s commented Jul 29, 2019

If current selection is empty document.execCommand('copy') may return false in some browsers (e.g. WebKit based ones).

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);
Copy link
Collaborator

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.

Copy link
Contributor Author

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'.

@@ -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')));
Copy link
Collaborator

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.

Copy link
Contributor Author

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 :-)

@aslushnikov aslushnikov merged commit 1b4a030 into puppeteer:master Jul 30, 2019
@yury-s yury-s deleted the execComand-test branch August 16, 2019 16:39
rfojtik pushed a commit to rfojtik/puppeteer that referenced this pull request Dec 21, 2019
…nd (puppeteer#4772)

If current selection is empty document.execCommand('copy') may return false in some browsers (e.g. WebKit based ones).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants