Hello, Welcome to Selenium Tutorials, In this post, we will see how to perform Flash testing with selenium.
If you ask me that do we have some plugin for this or some additional classes then my answer is no. We have to write separate code for this and we have to use the same. I have added a jar file in this post which contains the code already so you can directly use the same.
Partially we can do the same using Sikuli as well which is used for Game animation as well. This is mostly asked interview questions as well.
Sometime in your application, you may find some scenario where you need to check particular video as working as per expectation or not, to test this type of application we need to write some script to check the functionality of flash.
How to do Flash Testing with Selenium
We have some pre-defined method available for you tube flash application for example
1- pauseVideo
2- playVideo
3- mute, unmute etc.
so we will use some of these methods and try to explore the same
Note- in case your application use some other flash content please ask the developer to provide documentation of the same.
Precondition-
1- Download Flash jar – Click here
2- Download complete source code-Click here
3- Please read YouTube API. Methods- https://developers.google.com/youtube/flash_api_reference
Program for- Flash Testing with Selenium
package Flash; import org.openqa.selenium.firefox.FirefoxDriver; public class Testyoutube { public static void main(String[] args) throws InterruptedException { // Open firefox browser FirefoxDriver driver = new FirefoxDriver(); // Maximize browser driver.manage().window().maximize(); // FlashObjectWebDriver is seperate class which is available inside jar which we have //attached FlashObjectWebDriver flashApp = new FlashObjectWebDriver(driver, "movie_player"); // Pass the URL of video driver.get("https://www.youtube.com/watch?v=7igozQAdBMs"); Thread.sleep(2000L); // let the video load while (Integer.parseInt(flashApp.callFlashObject("getPlayerState")) == 3){ Thread.sleep(1000L); } // Play the video for 10 seconds Thread.sleep(10000); // pause video using pauseVideo method flashApp.callFlashObject("pauseVideo"); Thread.sleep(5000); // play video using playVideo method flashApp.callFlashObject("playVideo"); Thread.sleep(5000); // Seek to is method which will forword video to 140 second flashApp.callFlashObject("seekTo","140","true"); // Wait for 5 seconds Thread.sleep(5000); //mute video using playVideo method flashApp.callFlashObject("mute"); // Wait for 5 seconds Thread.sleep(5000); //set the volume of video using setVolume method flashApp.callFlashObject("setVolume","50"); // wait for 5 seconds Thread.sleep(5000); } }
Thanks for Visiting my blog. Please leave your comment below if you finding some issue.
Have a nice day 🙂
garima says
Hi,
Please see my test scenario below:
I need to launch youtube or any application having embedded video. and need to test below things:
1) Is video loaded
2) Is video running
3) are audio and video in sync
4) volumne up and down
5) All above scenarios by choosing full screen mode.
Please help
Mukesh Otwani says
Hi garima,
I am not that good in it 🙁 you can check youTube library may be you will get some methods for the same.
Rizvi says
I m getting error document.pauseVideo is not a method
Could you please help.me
Mukesh Otwani says
Hey Rizvi I think they have removed the method from the library. You can explore they must be having some different method name for this.
BG says
I’m getting below error message while running the above code. I have used below URL:
https://www.youtube.com/watch?v=qWp0pQlsJZc
document.movie_player is undefined
Mukesh Otwani says
Please check youtube documents for new methods.
Prabhu says
Hi Mukesh, Is it possible to fetch the data from flash object with ‘Object ID’.
Mukesh Otwani says
Hi Prabhu,
No idea on this but I don’t think we can get from Flash object using Selenium.
Khaja says
No Prabhu, you cannot directly interact with flash Object ID. There are few work arounds to it, one that Mukesh mentioned in this post. The reason that you cannot interact with flash is that all of the flash elements are embedded into one Object html element, and those flash elements are closed files and enclosed in a container on a webpage. This literally means that the flash is embedded into your html (or DOM) as a single file. Selenium WebDriver do not have a direct capability to interact with such elements. So, the first work around is to ask the developers to expose the flash object methods, so that you can interact with Selenium WebDriver (or to be more precise with JavaScript, you can use the JavascriptExecutor if you have your framework written in Java). Now, this is quite a tedious process, but the best of the best solutions available as of this moment.
The second way is to interact flash elements using mouse and keyboard combination using, Actions class. This can fail your scripts, if the x and y co-ordinates are not met. The same applies with the Robot class as well.
The third, and second best solution is to use image recognition api like Sikuli. This is an evolving api, so you may have to explore more on this.
I am trying to find, if Selenide (the selenium wrapper) has got any way of interacting with flash objects. If i find any, will let you know.
Raja says
Thanks dude, for making others job easy..
Mukesh Otwani says
Thanks Raja 🙂