cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Failed to enter full screen of video player

Open lawked opened this issue 7 years ago • 18 comments

  • Operating System: mac OS High Sierra 10.13.2 (17C88)
  • Cypress Version: 1.4.1
  • Browser Version: Google Chrome 63.0.3239.132 (Official Build) (64-bit)

Is this a Feature or Bug?

bug

Current behavior:

Given a html video player When I press the full screen button Then the video player DOES NOT GO to full screen ...and then I can see the message in the console: Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.

Desired behavior:

Given a html video player When I press the full screen button Then the video player SHOULD GO to full screen

How to reproduce:

1. open https://plyr.io/ or any other html video player 2. press full screen button

Test code:

describe('having video player in in-site mode', () => {
  it('should go to full screen after pressing full screen button', () => {
    cy.visit('https://plyr.io/');
    cy.get('[data-plyr="fullscreen"]').click();
  });
});

Additional Info (images, stack traces, etc)

I know the user gesture problem is really common, and this is the default browser behaviour, but it would be great to make it working correctly in Cypress as it should simulate user journey on tested page/application.

lawked avatar Jan 22 '18 10:01 lawked

+1

dweight avatar Jan 22 '18 10:01 dweight

This is something that definitely requires our support of native browser events, as this cannot be done programatically: https://github.com/cypress-io/cypress/issues/311

jennifer-shehane avatar Jan 22 '18 17:01 jennifer-shehane

Doesn't chromium have a CLI switch to bypass "API can only be initiated by a user gesture"?

mightyiam avatar Jul 15 '19 08:07 mightyiam

I'm not fluent in C++. I've looked into Chromium code and I didn't find a way to bypass this check.

mightyiam avatar Jul 15 '19 08:07 mightyiam

Does anyone have fix this issue ? or do you need help to investigate on this

JulienKode avatar Jun 19 '20 09:06 JulienKode

For now I am testing this by stubbing requestFullscreen and exitFullscreen, and asserting they are called when I expect them to be.

eirikb-bbc avatar Jan 22 '21 09:01 eirikb-bbc

For now I am testing this by stubbing requestFullscreen and exitFullscreen, and asserting they are called when I expect them to be.

Can you show us how :)

missak-boyajian avatar Mar 04 '21 11:03 missak-boyajian

For now I am testing this by stubbing requestFullscreen and exitFullscreen, and asserting they are called when I expect them to be.

Can you show us how :)

This approach assumes you use getElementById to get the element you are calling requestFullscreen on, but it's a good starting point:

const stubFullscreenHandlers = (someDocument) => {
  cy.stub(someDocument, "fullscreenEnabled")
    .get(() => true)
    .as("doc:fullscreenEnabled");

  cy.stub(someDocument, "exitFullscreen").resolves().as("doc:exitFullscreen");

  const stubbedRequestFullscreen = cy.stub().resolves().as("requestFullscreen");

  const actualGetElementById = someDocument.getElementById;
  cy.stub(someDocument, "getElementById")
    .callsFake((elementId) => {
      const el = actualGetElementById.call(someDocument, elementId);
      el.requestFullscreen = stubbedRequestFullscreen;
      return el;
    })
    .as("doc:getElementById");
};

cy.document().then(stubFullscreenHandlers);

cy.visit(...)
// code making fullscreen request

eirikb-bbc avatar Mar 04 '21 11:03 eirikb-bbc

any update on this. I am stuck with my player testing in fullscreen. Thank you!

rmjjo avatar Mar 18 '21 17:03 rmjjo

any update for testing full screen button

arifozkan avatar Apr 11 '21 13:04 arifozkan

Hi all, I just came across this discussion, and I found one temporary solution till cypress comes up with something https://github.com/dmtrKovalenko/cypress-real-events

Using .realHover() and .realClick() on the element, you can still go in full screen, Works for me!

arora239 avatar May 19 '21 05:05 arora239

Upvote on this!

poponuts avatar May 19 '21 14:05 poponuts

+1 for this feature. Currently, I used the real-event workaround but native implementation would be much better.

rehmanuet avatar Oct 17 '21 13:10 rehmanuet

Waiting for this feature. Facing the same issue : Failed to execute 'requestFullscreen' on 'Element': API can only be initiated by a user gesture.

nehamittal3012 avatar Nov 16 '21 12:11 nehamittal3012

+1

DenseMo23 avatar Feb 14 '23 14:02 DenseMo23

Testing full screen is a need for us too

andreifilip123 avatar Mar 01 '23 14:03 andreifilip123

+1

przedab avatar Apr 25 '23 17:04 przedab

Hi all, I just came across this discussion, and I found one temporary solution till cypress comes up with something https://github.com/dmtrKovalenko/cypress-real-events

Using .realHover() and .realClick() on the element, you can still go in full screen, Works for me!

thanks a lot ! works for me

Marim99 avatar Feb 12 '24 08:02 Marim99

I ran across the docs recently on features gated by user activation and was reminded of this issue: https://developer.mozilla.org/en-US/docs/Web/Security/User_activation

We should be triggering a user activation event in order to more fully simulate browser behavior.

For the time being, using the https://github.com/dmtrKovalenko/cypress-real-events plugin to perform any action on the page (like clicking on a random div) should trigger user activation and make this full screen of the video player available.

jennifer-shehane avatar Feb 26 '24 20:02 jennifer-shehane