Skip to content

Commit 1b4a030

Browse files
yury-saslushnikov
authored andcommitted
fix(test): make sure selection is not empty before running copy command (#4772)
If current selection is empty document.execCommand('copy') may return false in some browsers (e.g. WebKit based ones).
1 parent 7406b18 commit 1b4a030

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

test/evaluation.spec.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ module.exports.addTests = function({testRunner, expect}) {
226226
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created');
227227
});
228228
it('should simulate a user gesture', async({page, server}) => {
229-
const result = await page.evaluate(() => document.execCommand('copy'));
229+
const result = await page.evaluate(() => {
230+
document.body.appendChild(document.createTextNode('test'));
231+
document.execCommand('selectAll');
232+
return document.execCommand('copy');
233+
});
230234
expect(result).toBe(true);
231235
});
232236
it('should throw a nice error after a navigation', async({page, server}) => {

0 commit comments

Comments
 (0)