Overview of Flash application
If you are looking for web application automation testing probably “Selenium” is one of the best open source tool available to perform the automation. But sometimes we may need to do some work around or alternative solutions to when using selenium to test the flash components in the application.
Requirements specify to use flash or flex to be used to make the web site look better, but it will be a challenging task for automation engineer because selenium doesn’t support to read or interact or perform actions on flash objects.
Flash is a multimedia software for creating graphical applications like animated images, video players, and audio players in a webpage.
Flash applications are embedded into HTML code using <object> and <embed>, flash functional methods are not displayed in HTML code .It uses JavaScript internally to call flash methods.
Flash application testing
Flash feature testing is a kind of white-box testing, flash methods are not exposed in HTML page. So, it’s difficult for automation tester to identify elements to perform actions.
Sample flash application in http://www.permadi.com/tutorial/flashjscommand
Flash application can be tested in two ways:
If the developers can provide recompiled application or software by adding some flash methods. Then below example shows the sample application complied with the flash methods
Step 1:
Create FlashWebDriver class which receives flash and perform user actions on flash application using JavaScript internally.
package com.java.selenium;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
public class FlashWebDriver
{
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:
Write the automation script for testing flash application using FlashWebDriver.
package com.java.selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Flash_Example
{
public static void main(String[] args) throws Throwable
{
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
FlashWebDriver flashapp=new FlashWebDriver(driver,"myFlashMovie");
driver.get("http://www.permadi.com/tutorial/flashjscommand/");
flashapp.callFlashObject("Play");
Thread.sleep(3000);
flashapp.callFlashObject("StopPlay");
}
}
Windows controls in Web Applications
Web applications testing sometimes involves uploading & downloading of varies types of documents like .txt, .doc, .docx. Windows popup appears, when user click on upload or download button on web application.
Functional testing tool like selenium doesn’t handle windows based popups while uploading & downloading documents. So, automation tester can chose “Auto IT” in order to handle windows based popups.
Auto IT
Steps to handle window based applications using Auto IT.
Application URL : http://www.pdfonline.com/convert-pdf/
Step: 1
Write Auto IT script in Auto IT Script Editor by mentioning details regarding window popup and data.
WinWaitActive("File Upload")
WinActivate("File Upload")
Local $file="C:\"&$CmdLine[1]
WinActivate("File Upload")
ControlSetText("File Upload","","Edit1",$file)
ControlClick("File Upload","","Button1")
Step: 2
Compile the Auto IT script file which is .au3 file, then .exe Auto IT file would be generated.
Step: 3
Now let’s invoke the autoit exe file from the standalone or our selenium code which to handle windows based applications or the popups.
package com.java.selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Fileupload_Windows
{
public static void main(String[] args) throws Throwable
{
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.pdfonline.com/convert-pdf");
WebElement k=driver.findElement(By.cssSelector("input[name*='Filedata']"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", k);
String[] command=new String[]{"C:/ FileUpload.exe","AutoTest_WordDoc.docx"};
Runtime.getRuntime().exec(command);
}
}
If you are looking for web application automation testing probably “Selenium” is one of the best open source tool available to perform the automation. But sometimes we may need to do some work around or alternative solutions to when using selenium to test the flash components in the application.
Requirements specify to use flash or flex to be used to make the web site look better, but it will be a challenging task for automation engineer because selenium doesn’t support to read or interact or perform actions on flash objects.
Flash is a multimedia software for creating graphical applications like animated images, video players, and audio players in a webpage.
Flash applications are embedded into HTML code using <object> and <embed>, flash functional methods are not displayed in HTML code .It uses JavaScript internally to call flash methods.
Flash application testing
Flash feature testing is a kind of white-box testing, flash methods are not exposed in HTML page. So, it’s difficult for automation tester to identify elements to perform actions.
Sample flash application in http://www.permadi.com/tutorial/flashjscommand
Flash application can be tested in two ways:
- Developer has to provide flash methods for testing, then we can perform testing by passing them through JavaScript code.
- Independent testers doesn’t have access to source code, can use image based tool called Sikuli, which uses images to perform user actions.
If the developers can provide recompiled application or software by adding some flash methods. Then below example shows the sample application complied with the flash methods
Step 1:
Create FlashWebDriver class which receives flash and perform user actions on flash application using JavaScript internally.
package com.java.selenium;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
public class FlashWebDriver
{
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:
Write the automation script for testing flash application using FlashWebDriver.
package com.java.selenium;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Flash_Example
{
public static void main(String[] args) throws Throwable
{
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
FlashWebDriver flashapp=new FlashWebDriver(driver,"myFlashMovie");
driver.get("http://www.permadi.com/tutorial/flashjscommand/");
flashapp.callFlashObject("Play");
Thread.sleep(3000);
flashapp.callFlashObject("StopPlay");
}
}
Windows controls in Web Applications
Web applications testing sometimes involves uploading & downloading of varies types of documents like .txt, .doc, .docx. Windows popup appears, when user click on upload or download button on web application.
Functional testing tool like selenium doesn’t handle windows based popups while uploading & downloading documents. So, automation tester can chose “Auto IT” in order to handle windows based popups.
Auto IT
Steps to handle window based applications using Auto IT.
Application URL : http://www.pdfonline.com/convert-pdf/
Step: 1
Write Auto IT script in Auto IT Script Editor by mentioning details regarding window popup and data.
WinWaitActive("File Upload")
WinActivate("File Upload")
Local $file="C:\"&$CmdLine[1]
WinActivate("File Upload")
ControlSetText("File Upload","","Edit1",$file)
ControlClick("File Upload","","Button1")
Step: 2
Compile the Auto IT script file which is .au3 file, then .exe Auto IT file would be generated.
Step: 3
Now let’s invoke the autoit exe file from the standalone or our selenium code which to handle windows based applications or the popups.
package com.java.selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Fileupload_Windows
{
public static void main(String[] args) throws Throwable
{
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://www.pdfonline.com/convert-pdf");
WebElement k=driver.findElement(By.cssSelector("input[name*='Filedata']"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", k);
String[] command=new String[]{"C:/ FileUpload.exe","AutoTest_WordDoc.docx"};
Runtime.getRuntime().exec(command);
}
}