Category Archives: SELENIUM FLASH TESTING

* Selenium Automation Learning Path *

Selenium learning Path

Selenium learning Path

selenium flash automation

Please Refer this blog entry

Please Refer this blog entry

flash automation using selenium

Please Refer this blog entry

Please Refer this blog entry

selenium flex testing

Please Refer this blog entry

Please Refer this blog entry

flex automation using selenium webdriver

Please Refer this blog entry

Please Refer this blog entry

how to automate flash application with selenium webdriver? Example 3

 

Get the code

Link1

Link2

 

FlashObjectWebDriver.java

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;


public class FlashObjectWebDriver {
 private final WebDriver webDriver;
 private final String flashObjectId;

public FlashObjectWebDriver(final WebDriver webDriver, final String flashObjectId) {
 this.webDriver = webDriver;
 this.flashObjectId = flashObjectId;
 }

public String click(final String objectId, final String optionalButtonLabel) {
 return callFlashObject("doFlexClick", objectId, optionalButtonLabel);
 }

public String click(final String objectId) {
 return click(objectId, "");
 }

public String callFlashObject(final String functionName, final String... args) {
 final Object result =
 ((JavascriptExecutor)webDriver).executeScript(
 makeJsFunction(functionName, args),
 new Object[0]);

return result != null ? result.toString() : null;
 }

private String makeJsFunction(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);
 }

}

 

Color_shawkath.java

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;


public class Color_shawkath {


 private final static String GREEN = "GREEN";
 private final static String BLUE = "BLUE";
 private final static String RED = "RED";
 private final static String URL = "http://tinyurl.com/c937qt7";

 @Test
 public void TestColor() throws InterruptedException{
 FirefoxDriver driver = new FirefoxDriver();
 driver.manage().window().maximize();
 FlashObjectWebDriver flashApp = new FlashObjectWebDriver(driver, "coloredSquare");

 driver.get(URL);

 //Assert.assertEquals("Clicking Colors", driver.getTitle());

 Assert.assertEquals(GREEN, flashApp.callFlashObject("getColor"));
 flashApp.callFlashObject("click");
 Thread.sleep(10000L);
 Assert.assertEquals(BLUE, flashApp.callFlashObject("getColor"));
 flashApp.callFlashObject("click");
 Thread.sleep(10000L);
 Assert.assertEquals(RED, flashApp.callFlashObject("getColor"));
 flashApp.callFlashObject("click");
 Thread.sleep(10000L);
 Assert.assertEquals(GREEN, flashApp.callFlashObject("getColor"));

 driver.quit();
 }


}

How to automate youtube using selenium Webdriver?

youtube flash player automation using selenium WebdriverWay2 - youtube flash player automation using selenium Webdriver

 

 

 

 

 

 

 

 

 

 

Step 1 : Create new class named FlashObjectWebDriver.java

 

public class FlashObjectWebDriver {
 private final WebDriver webDriver;
 private final String flashObjectId;

public FlashObjectWebDriver(final WebDriver webDriver, final String flashObjectId) {
 this.webDriver = webDriver;
 this.flashObjectId = flashObjectId;
 }



public String callFlashObject(final String functionName, final String... args) {
 final Object result =
 ((JavascriptExecutor)webDriver).executeScript(
 makeJsFunction(functionName, args),
 new Object[0]);

return result != null ? result.toString() : null;
 }

private String makeJsFunction(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: Make new class and paste following code to automate YouTube player.

import org.openqa.selenium.firefox.FirefoxDriver;
public class Youtube {
 public static void main(String[] args) throws InterruptedException {
 FirefoxDriver driver = new FirefoxDriver();

FlashObjectWebDriver flashApp = new FlashObjectWebDriver(driver, "movie_player");

driver.get("http://tinyurl.com/bqnaoo7");
 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(5000);
 flashApp.callFlashObject("pauseVideo");
 Thread.sleep(5000);
 flashApp.callFlashObject("playVideo");
 Thread.sleep(5000);
 flashApp.callFlashObject("seekTo","140","true");
 Thread.sleep(5000);
 flashApp.callFlashObject("mute");
 Thread.sleep(5000);
 flashApp.callFlashObject("setVolume","50");
 Thread.sleep(5000);

}

}

Things to KNOW:

Google has expose functions used to handle YouTube flash player

@

YouTube ActionScript 3.0 Player API Reference
player.playVideo():Void
player.pauseVideo():Void
player.stopVideo():Void
player.seekTo(seconds:Number, allowSeekAhead:Boolean):Void
player.nextVideo():Void
player.previousVideo():Void
player.mute():Void
player.unMute():Void
player.isMuted():Boolean
player.setVolume(volume:Number):Void
player.getVolume():Number
player.setSize(width:Number, height:Number):Void
player.getPlaybackRate():Number
player.setPlaybackRate(suggestedRate:Number):Void

and many more …………..

Get the code from

Link1

Link2

How to do flash Testing using Selenium WebDriver? Example 1

Please read before this

How to do flash Testing using Selenium WebDriver?

After reading above you know that there is one class which is having capability to automate flash app.

So now we should know following things before start implementation of our example.

1. we can’t access flash objects using Xpath using firebug.

Flash can't access by xpath using firebug

 

 

 

 

 

 

 

 

 

2. To perform action developer should assign appropriate object ID.

Firefox firebug - Get Object ID for permadi - flashjscommand app

 

 

 

 

 

 

 

 

 

 

3. Developer should expose all flash functions which are used to test flash application.

Sample Flash APP
Play Button
Flash method being used: Play()
Stop Button
Flash method being used: StopPlay()
Rewind Button
Flash method being used: Rewind()
NextFrame Button
Flash method being used: TGetProperty(nameOfTargetMovieClip, propertyIndex) and GotoFrame(frameNum)
Zoomin Button & Zoomout Button
Flash method being used: Zoom(relative percentage)
Send Data
Flash method being used: SetVariable(variableName, variableValue)
Receive Data
Flash method being used: GetVariable(variableName)

 

4.  how to communicate between Adobe Flash objects and Javascript ?

We have one class which is helpful to call functions of flash by making run-time JavaScript functions – Check out LINK

FlashObjectWebDriver class and constructor mapping with object ID

How call functions works in FlashObjectWebDriver

 

 

 

 

 

 

 

 

 

5. Make one new class named FlashObjectWebDriver.java

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
public class FlashObjectWebDriver {
 private final WebDriver webDriver;
 private final String flashObjectId;

public FlashObjectWebDriver(final WebDriver webDriver, final String flashObjectId) {
 this.webDriver = webDriver;
 this.flashObjectId = flashObjectId;
 }

public String callFlashObject(final String functionName, final String... args) {
 final Object result =
 ((JavascriptExecutor)webDriver).executeScript(
 makeJsFunction(functionName, args),
 new Object[0]);

return result != null ? result.toString() : null;
 }

private String makeJsFunction(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);
 }

}

6. Now make new class to test our example

import org.openqa.selenium.firefox.FirefoxDriver;

public class permadi_INTERACTION_WITH_JAVASCRIPT {

 public static void main(String[] args) throws InterruptedException {
 FirefoxDriver driver = new FirefoxDriver();

 driver.get("http://www.permadi.com/tutorial/flashjscommand/");
 driver.manage().window().maximize();
 FlashObjectWebDriver flashApp = new FlashObjectWebDriver(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"));

 }

}

8. Observe test execution on browser

Please download code from

Link1

Link2

how can we get flash object ID of flash movie / flash app?

Prerequisite 

Please install firebug on Firefox / Google chrome 

What is <object>tag ?

The <object> tag defines an embedded object within an HTML document. Use this element to embed multimedia (like audio, video, Java applets, ActiveX, PDF, and Flash) in your web pages.

You can also use the <object> tag to embed another webpage into your HTML document.

References

Please Refer this

 

 

 

 

 

Please refer this example to know Object Tag – Example 

object tag example - Can't give source code in right click options

object tag example – Can’t give source code in right click options

 

 

 

 

 

 

 

What is  embed tag ?

The tag defines a container for an external application or interactive content (a plug-in).

Example 1

References

Please refer to know about embed tab

 

 

 

 

 

 

 

Example 2

Example 2 - Embed Tag ActionscriptJavascriptCommunication.

 

 

 

 

 

 

 

 

Example 3

Find object name coloredSquare help to find flash object on HTML web page.

Example - Embed Tag

 

 

 

 

 

 

 

 

Example 4

check out object name myFlashMovie which is used to locate flash object on webpage.

Example INTERACTION WITH JAVASCRIPT - Embed Tag

 

 

 

 

 

 

 

Example 5

Example flashjavascript.- Embed Tag

 

 

 

 

 

 

 

 

 

Example 6

check out for movie_player name of the object. which is useful for automate youtube player

Example od youtube - Embed Tag

How to do flash Testing using Selenium WebDriver?

Flash testing is not normal automation testing.

Flash is not part of HTML webpage. Its embed object on HTML webpage.

So its not possible to get xpath of element on the flash movie / flash.

Selenium RC has extension FlexUISelenium  that enables the Selenium RC client drivers to interact (and test) the Flex UI components and methods of the Flex application.

you can download jar and include them into project and get functions to communicate with Flash. flash-selenium.jar

But there is not any extension available for Selenium Webdriver

So we do smart work here. We rewrite FlashSelenium.java for selenium Webdriver.


import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;

public class FlashSeleniumWebDriver {
 private final WebDriver webDriver;
 private final String flash_ObjectId;

//constructor for FlashSeleniumWebDriver
 public FlashSeleniumWebDriver(final WebDriver webDriver, final String flash_ObjectId) {

//initialize webDriver variable to use in this class methods
 this.webDriver = webDriver;

 //initialize flashObjectId variable which have real flash object ID to use in this class methods
 this.flash_ObjectId = flash_ObjectId;
 }

public String call(final String functionName, final String... args) {


 final Object result =
 ((JavascriptExecutor)webDriver).executeScript(
 makeJavaScriptFunction(functionName, args),
 new Object[0]);

return result != null ? result.toString() : null;
 }

private String makeJavaScriptFunction(final String function_Name, final String... args) {
 final StringBuffer function_Args = new StringBuffer();

if (args.length > 0) {
 for (int i = 0; i < args.length; i++) {
 if (i > 0) {
 function_Args.append(",");
 }
 function_Args.append(String.format("'%1$s'", args[i]));
 }
 }
 return String.format(
 "return document.%1$s.%2$s(%3$s);",
 flash_ObjectId,
 function_Name,
 function_Args);
 }

}

 

Pupunzi

For a better web

Tech

News and reviews from the world of gadgets, gear, apps and the web

VentureBeat

News About Tech, Money and Innovation

Digital Inspiration

Tips and tutorials around all things tech.

Thinkwareglobal's Blog

Just another WordPress.com weblog

Kenazari's Blog

Just another WordPress.com weblog

Richfowler1's Blog

Just another WordPress.com weblog

Romaicus's Blog

Just another WordPress.com weblog

botlaguduri

Just another WordPress.com site

chandanag89

Just another WordPress.com site

meghshetty

Just another WordPress.com site

digitalmediaexpert

digital media expert blog

Thinking in Silverlight

Silverlight/WPF/Windows 8 Store App

Different Journeys

Let's make life easier!

LAW RESOURCE INDIA

LEGAL RESOURCE CENTRE / COURT JUDGMENTS / LEGAL ARCHIVES

BookConnect

Promoting Indian language Books

Mary Ann M-P's Blog

Selenium: My Take

Actively Lazy

Software, crafted with passion

SAPonPower

An ongoing discussion about SAP infrastructure

SAP Career

Your Career Mentor

hrsapcertification

Just another WordPress.com site

The secret product manager

Thoughts about product management, SUSE, Linux, ARM processors, Cloud, AIX, Power Systems, and other things that interest me

Sap Certification Material . Com

Quality store for sap software and courses

Simon Les Flex's Blog

SAP Process Integration Specialist - NOW WE CAN DO BETTER!

Oracle Technologies Primer

An Oracle Fusion Middleware and iPaaS blog!

Gilberto Holms

Java, Middleware, SOA Architecture Blog

The Skeleton

Java code skeletons, tips and pointers

J@n van Zoggel

integration, innovation & random technology stuff

The Pragmatic Integrator

Hints and tips from a pragmatic integration specialist

briskwalk

The pace of life..

Optimalbg's Blog

Just another WordPress.com site

IT Jobs in USA

Keep the track of this Blog if you are looking out for some good Opportunities to work in USA....

Referral Jobs | Right Place to Get a Job

Hurry you are one Click away to get a job - Fresher Jobs for 2012, 2013 fresher’s and also high paid jobs for well Experienced IT professionals on Referal jobs.

eccinternational.wordpress.com/

ISO Consulting | ISO 27001 | ISO 20000 | CMMI | BCM | GRI Sustainability Reporting & Assurance | eLearning | Trainings | Philippines

Michael Korn's Blog

Musings on Life, Career, Faith and Technology

WORKINGWITHQTP

Just another WordPress.com weblog

Solutions365

.net, WCF, Unity, IOC, SQL

SQA and Testers Blog

Just another WordPress.com weblog

Expertqtp's Weblog

Just another WordPress.com weblog

Sai Chamarthi

Experienced Testing Professional

saxenavinay

A great WordPress.com site

Suresh4qtp's Blog

Just another WordPress.com site

jonah95hill

This WordPress.com site is the cat’s pajamas

It's always something...

Just another WordPress.com weblog

Faculty of Information Technology - Lê Ngọc Tiến

Be Yourself! Simplify Our Goals! Nothing is Impossible!

Anti-Malware Testing

Thoughts on security product testing past and present

Methods & Tools

Practical knowledge for the software developer, tester and project manager