testcafe

Is there a way to handle a Chrome popup to allow for a shared clipboard?


We are trying to copy and paste some text for some of our functionality and there is Chrome popup that keeps coming up and preventing further action right before the text can be pasted. It's the allow shared clipboard popup. Is there a way to handle this programmatically or via some Chrome flag?

import { Selector } from 'testcafe';

const editor = Selector('div[class="full-bleed-uic-editor editor editable"]');

fixture`copy and paste`
  .meta({
    fixtureID: 'f-0001',
    author: '',
    app: '',
  })
  .beforeEach(async (t) => {
    console.log('Copy and paste');
  });

test.meta({
  priority: 'p1',
  testID: 't-0001',
  testType: 'Smoke',
  testRailCaseId: '',
})('Copy and paste', async (t) => {
    await t.navigateTo('https://www.chegg.com');
    await t.click(editor);
    await t.typeText(editor, 'Python is very easy programming language');
    await t.pressKey('ctrl+a ctrl+c ctrl+v ctrl+v');
});

This is the popup that's stopping the copy and paste action.

Allow clipboard popup

If we manually accept it and then rerun the test in the same window, everything works as expected.

Any help would be appreciated, thanks!


Solution

  • I managed to suppress the popup using the following method:

      .beforeEach(async (t) => {
    
        const cdpClient = await t.getCurrentCDPSession();
    
        await cdpClient.Browser.grantPermissions({ permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite']});
    
      });
    

    You can read more about this method in Chrome DevTools Protocol - Browser domain