Testing the functionality of the flash is called Flash Testing. Sometimes in your application, you may have to check the particular animation videos, movies, games, etc. as working as per expectation or not. Here we need to write the script to check the functionality of flash to test this type of application. Flash is a software developed by Macromedia which is now acquired by Adobe. It is used to develop video games, movies, Mobile games for iOS and Android, etc. To play the Flash applications we need some plugins.
We should be ready with the below requirements to test the flash application with Selenium WebDriver. Here is the list of pre-requisites:
Below the editor software required for flash applications.
To play the Flash applications we need the following plugins that are listed as follows:
Below are the Testing tools required in flash testing.
In general, to interact with your Flash content in Selenium it doesn’t have an interface. In ActionScript, Flash files are programmed which are very similar to JavaScript. Flash files also contain programming Elements. For E.g. they too have buttons, text box, radio buttons, etc. The Flash file needs to call some internal methods to perform the task. For example, the flash content of a button may cause the background color of flash content to change. To the rescue we use the ActionScript, it exposes a class called External Interface for the developers. This class is most important if you want to expose the Flash file internal methods to the outside world. The outside world is the Browser that is hosting the content. So if we expose our internal methods from Flash file to the Browser then we can call them directly using JavaScript.
Flash Applications can be tested in two ways Manual & Automation:
Manual: It is simple and easy to test by executing the test cases manually to test the Flash object.
Automation: To execute the script, we need to write a script using automation tools like TestComplete, Selenium, SoapUI, and Test Studio.
Flash is embedded in SWF files where other elements are embedded in HTML files. So, that is why compared to flash HTML is easy to capture.
In all Web pages, the < object >tag defines an embedded object with any multimedia like Video, ActiveX, Flash, Java applets, ActiveX, PDF, etc. in your web pages. It indicates “embed” within an HTML document. This tag describes a container embedded in < object />or < embed />tags in an HTML for interactive content or external application. To locate the flash object on webpages the object name is used. You can also use the tag to embed another webpage into your HTML document.
For example, the flash movie is defined in an “embed” tag in HTML document or file.
Example:
/* Html page*/
To import the Flash library, you need to download the Flash Selenium jar file. Once downloading is completed, you need to add the jar file to your project.
Once all the required pre-requisites are finished, then you need to call FlashObjectWebDriver class. This class is used to perform the actions on Flash players.
Syntax:
FlashObjectWebDriver flash = new FlashObjectWebDriver(webDriver, “ flash object”);
Flash application can be tested in two ways:
Below sample, the program acts as a video player
There are some pre-defined methods available for testing youtube flash applications.
Example:
Step1: Write a Selenium script in eclipse and execute it. The below code will perform the following things when we execute the script.
If the developers provide some flash methods then the below example shows the sample application complied with the flash methods.Step 1:
Create FlashWebDriver class and perform user actions on the flash application using JavaScript internally.
package com.java.selenium; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; public class FlashTesting < private final WebDriver webdriver; private final String flashObjectId ; public FlashWebDriver(final WebDriver webdriver,final String flashObjectId) < this.webdriver=webdriver; this.flashObjectId=flashObjectId; > public String click(final String objectId,final String buttonLabel) < return callFlashObject("DoFlashClick",objectId,buttonLabel); > public String click(final String objectId) < return callFlashObject(objectId,""); > public String callFlashObject(final String functionName,final String. args) < final Object result=((JavascriptExecutor) webdriver).executeScript (makeJsFuntion(functionName,args), new Object[0]); return result!=null ? result.toString() :null; > private String makeJsFuntion(final String functionName,final String. args) < final StringBuffer functionArgs=new StringBuffer(); if(args.length>0) < for(int i=0;iif(i>0) < functionArgs.append(","); >functionArgs.append(String.format("'%1$s'", args[i])); > > return String.format("return document.%1$s.%2$s(%3$s);", flashObjectId, functionName,functionArgs); > >
Step 2:
package com.java.selenium; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class FlashTesting < public static void main(String[] args) throws InterruptedException < WebDriver driver; System.setProperty("webdriver.gecko.driver", "C:\\drivers\\geckodriver.exe"); driver = new FirefoxDriver(); driver.get("http://www.permadi.com/tutorial/flashjscommand/"); driver.manage().window().maximize(); FlashWebDriver flashApp = new FlashWebDriver(driver, "myFlashMovie"); flashApp.callFlashObject("Play"); // first number Thread.sleep(3000L); flashApp.callFlashObject("StopPlay"); // operation Thread.sleep(3000L); flashApp.callFlashObject("Rewind"); System.out.println(flashApp.callFlashObject("GetVariable","/:message")); flashApp.callFlashObject("SetVariable","/:message","Learn Flash testing with Webdriver"); System.out.println(flashApp.callFlashObject("GetVariable","/:message")); > >
Step 2: Execute the above script.
Output: Once we execute the above script the video starts to play, stop, and, rewind the video.
Challenges in Flash Testing