All IT Courses 50% Off
Selenium Tutorials

Flash Testing with Selenium WebDriver

What is Flash Testing?

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.

Pre-Requisites for Flash Testing with Selenium WebDriver

We should be ready with the below requirements to test the flash application with Selenium WebDriver. Here is the list of pre-requisites:

  • Flash Web Application
  • Adobe Flash Player plugins
  • Native browser support

Below the editor software required for flash applications.

  • Adobe Animate
  • Flash Builder
  • Flash Develop
  • Power Flasher
  • Scaleform

To play the Flash applications we need the following plugins that are listed as follows:

  • OpenFL
  • Adobe Air
  • Flash Player
  • Gnash

Below are the Testing tools required in flash testing.

All IT Courses 50% Off
  • Selenium
  • TestComplete
  • Soap UI
  • Test Studio etc.

How to test Flash content using Selenium?

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. 

Different ways to test Flash Applications

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.

Difference between the Flash and other elements

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.

How can you get a flash movie or flash app object ID?

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 <object> 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*/
<html>
<body marginwidth="0" marginheight="0">
<embed width="100%" height="100%" name="plugin" src="http://video/movieplay.swf" type="application/flash"/>
</body>
</html>

How to perform Flash Testing using Selenium Webdriver?

To import the Flash library, you need to download the Flash Selenium jar file. You can download the Flash.jar file for Selenium WebDriver through the link https://drive.google.com/drive/folders/0B5v_nInLNoquN3hRbmJFYXpCb28. 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:

  • Developer will provide flash methods for testing, bypassing them through JavaScript code.
  • Independent testers don’t have access to source code provided by developers, So testers use an image-based tool called Sikuli, which uses images to perform user actions.

Creation of selenium script for Flash Testing.

Below sample, the program acts as a video player

There are some pre-defined methods available for testing youtube flash applications. 

  1. playVideo
  2. pauseVideo
  3. mute
  4. setVolume
  5. seekTo

Example:

Step1: Write a Selenium script in eclipse and execute it. The below code will perform the following things when we execute the script.

  1. Launch the Chrome browser
  2. Launch the site
  3. Play the video
  4. Stop the video
  5. Rewind the video

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;i<args.length;i++)
  {
 if(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

  • To automate the flash application, you can use FlexMonkium which is an add-on for Selenium IDE.
  • Using Selenium-Flexmonkium integration you might face an issue to enable record/playback Flex apps. To overcome the issue the user needs to install and integrate Flexmonkium to selenium IDE very carefully. Proper installation will enable the record to automate flash apps.

Conclusion:

  • In Flash testing, you need to check the particular animation videos, movies, games, etc. as working as per expected or not
  • The difference between flash and other element is that Flash is embedded in SWF files, whereas other elements are embedded in HTML files
  • To locate the flash object you use attributes like object id. And therefore you can perform operations like play, stop, mute, resume, etc.
  • Testing tools required in flash testing.
  1. Selenium
  2. TestComplete
  3. Soap UI
  4. Test Studio etc.
  • To play the Flash applications we need the following plugins that are listed as follows:
  1. OpenFL
  2. Adobe Air
  3. Flash Player
  4. Gnash
Facebook Comments

Related Articles

Back to top button