Amol
Amol

Reputation: 303

How to check if video is playing if we have video URL?

I am writing a java class where i have some video URLs . I want to check if the video is played or not . In other words i just need to validate the video URL I have heard we can use Selenium for this but i have no idea.

Thanks in Advance

Upvotes: 1

Views: 10538

Answers (2)

Kushal Bhalaik
Kushal Bhalaik

Reputation: 3384

If your video is playing using html5 tag and are using selenium then you can check that as following:

driver.findElement(by.xpath("Video element")).getAttribute("currentTime");

if it is greater than 0 that means those many seconds of playback o/w:

driver.findElement(by.xpath("Video element")).getAttribute("ended");

will show if playback has ended.

Upvotes: 5

Densetsunobaka
Densetsunobaka

Reputation: 107

Selenium is a web driver that works by inspecting the DOM and interacting with the browser so I am assuming your java class ends up generating a web page.

I've never tried to interact with a video player before but assuming you are using html5 for your player you should be able to play the video by getting the play button element from the page and actioning a click on it. To verify that it actually plays you could wait a few seconds then verify via the progress bar that the current point in the video is past the 0:00 moment.

The above said, if these videos are external URLs you should avoid testing them, your testing should refrain to what is within the scope of your application, IE check that a video player is on the page, and confirm that it points at the expected link, but not that external resources are available (IE that a random video is still available on YouTube).

Upvotes: 0

Related Questions