0

In my web application built with Angular, I have a <video> element that I would like to test using Protractor.

What I need to do is

1) Play and pause the video

2) Assert whether the video is playing or not

How can I accomplish this?

Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
  • Can you share HTML before clicking the play button, after clicking the pause button and when the video is over? – Kuba Lubas Apr 24 '19 at 13:33

1 Answers1

2

Yes , its possible. There is a HTML element paused which returns a boolean and tells if the video is paused or playing.

Below is the code I am using and it works like charm.

 async returnVideoState() {
    let pausedState = browser.executeScript(() => {
      return document.getElementsByClassName('videoelm').paused;
    });
    return pausedState;
  }


    async assertIfVideoIsPlaying(bool) {
    _isPaused = await this.returnVideoState();
    expect(_isPaused).toBe(bool);
  }

Usage:

   async pauseVideo() {
await this.pauseVideo();
await this.assertIfVideoIsPlaying(true);
  }

When video is Paused it should return true and false when being played.

Ninja
  • 130
  • 1
  • 9