Selenium for Flash/Flex Automation

When you want to automate your web application which is using Flash/Flex component for animation, video, and interactivity to web pages. Selenium supports Flash/Flex automation using ‘Adobe Flash Builder’ tool. This is a licensed tool.

Objective of this blog is to implement automation for Flash/Flex application.

Any online available Flash/Flex application cannot be automated using ‘Adobe Flash Builder’ with ‘Selenium’. Reason being, we will not be able to identify the objects of Flash/Flex application available online. Hence access to Source code of Flash/Flex application‘ OR ‘Application Action Script API Reference document‘ is must for the automation.

Here we will automate one of the ‘YouTube’ application. For which Google Developers as published the ‘YouTube Action Script 3.0 Player API Reference’. Below is the URL for Action Script API Reference document.

https://developers.google.com/youtube/flash_api_reference

Adobe Flash Builder can be downloaded from the below URL

https://www.adobe.com/cfusion/tdrc/index.cfm?product=flash_builder

Download the ‘Adobe Flash Builder’ in required language support & platform for ‘Windows’ or ‘Mac’ OS version. Install the downloaded version, installed version looks similar to open source ‘Eclipse IDE’ tool.

Flash-Selenium components for automation can be downloaded from below URL

http://code.google.com/p/flash-selenium/downloads/list

Download the required Flash component, based on which Scripting language you will be use for automation (Java, C #, PHP, Ruby etc). We will be using Java for automation script, which can be downloaded from below URL

http://flash-selenium.googlecode.com/files/flash-selenium.jar

Create a New Java Project in ‘Flash Builder’ & configure the Java build path with ‘selenium-server-standalone-2.24.1.jar’ & ‘flash-selenium.jar

Copy & paste the below java code to New Java Project Created, which is written using JUnit for testing the YouTube Flash Application.

package flash.test;
import org.junit.*;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.FlashSelenium;
import com.thoughtworks.selenium.Selenium;
public class Flash_youtube {
private final static String BASE_URL = “http://www.youtube.com”;
private final static String PAGE = “/watch?v=efRNKkmWdc0”;
private Selenium selenium;
private FlashSelenium flashApp;

@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”,BASE_URL);
selenium.start();
Thread.sleep(10000L);
flashApp = new FlashSelenium(selenium, “movie_player”);
selenium.open(PAGE);
selenium.windowMaximize();
}

@After
public void tearDown() throws Exception {
selenium.stop();
}

@Test
public void verifyFlexAppSumIsCorrect() throws Exception {

// wait till video load – buffering (3)
while (Integer.parseInt(flashApp.call(“getPlayerState”)) == 3){
Thread.sleep(1000);
}

// Play the video for 10 seconds
Thread.sleep(5000);
flashApp.call(“pauseVideo”); //Pause the Video
System.out.println(“After pauseVideo”);
Thread.sleep(5000);
flashApp.call(“playVideo”); //Play the Video
Thread.sleep(5000);
System.out.println(“After playVideo”);
flashApp.call(“seekTo”,”140″,”true”); //Seek to 140 sec
Thread.sleep(5000);
System.out.println(“After seekTo”);
flashApp.call(“mute”); //Mute the Video
Thread.sleep(5000);
flashApp.call(“setVolume”,”80″); //Set the Volume to 80%
Thread.sleep(50000);
}
}

In the HTML source code, ‘Flash/Flex component’ will be added to the web page.

Providing the Selenium & Flash/Flex instance to FlashSelenium object :

flashApp = new FlashSelenium(selenium, “movie_player”);
movie_Player’ is the tag id of Flash/Flex component of Embed or Object tag.

Note: Embed or Object tag is used in the HTML code to add the Flash/Flex component in the web page. Embed or Object tag id & Selenium object instance must be passed to ‘FlashSelenium’ API.

Start the Selenium Server & Run ‘Flash_youtube.java’ as Junit Test. YouTube Play, Pause, SeekTo, Mute, SetVolume functions are executed.

Advantage of using ‘Adobe Flash Builder’ tool, it support Java projects, which give the flexibility to port the Java frame work for Flash/Flex automation.

For any Flash/Flex automation, access to ‘Source code’ or ‘Action Script API Reference’ is must. This is required for automation code to call the Right API with correct parameters to invoke the Flash/Flex functions.

About testxpress

Working @ SPI.
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Selenium for Flash/Flex Automation

  1. Jeevan says:

    How to automate, when player don’t have functions (OOPS)? Ooyala Player version 2, doesnt have these.
    I went to this website and I couldnt automate videos here.
    http://www.mytonomy.com

    • testxpress says:

      I inspected the application, all the videos is having the id, selenium click will work there. To automation player functionality, Access to ‘Source code’ or ‘Action Script API Reference’ is must. Once we get to know the correct values of play, pause, stop etc. Then using ‘Adobe Flash Builder’ you can automate the application, which are embedded in ‘Object’ tag.

Leave a comment