Sunday, 3 August 2014

Automating Flash applications and Windows controls using Selenium



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:


  • 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);


}
}

30 comments:

  1. The blog gaveidea to automate flash and windows control using selenium
    My sincere thanks for sharing thos post
    Selenium Training in Chennai

    ReplyDelete
  2. really you have been shared informative blog. it will be really helpful to many peoples. so keep on sharing such kind of an interesting blogs.
    selenium training in chennai

    ReplyDelete
  3. It was very nice blog to learn about Selenium.Thanks for sharing new things. You are doing a great job. You inspire me to write for other. Thank you very much. Selenium Training in Chennai | Software Testing Training in Chennai

    ReplyDelete
  4. Thanks for sharing great information in your blog. Got to learn new things from your Blog . It was very nice blog to learn about Selenium.


    Software Testing Training in Bangalore

    Software Testing Training in BTM Layout


    Software Testing Training in Marathahalli

    ReplyDelete
  5. Nice blog has been shared by you. it will be really helpful to many peoples who are all working under the technology.thank you for sharing this blog.

    Software Testing Training in Marathahalli|
    Software Testing Training in Bangalore|

    ReplyDelete
  6. I have read your blog and I gathered some needful information from your blog. Keep update your blog. Awaiting for your next update.
    Software Testing Training in Marathahalli|
    Software Testing Training in Bangalore|

    ReplyDelete
  7. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up selenium Online Training Bangalore

    ReplyDelete
  8. 3D Animation Training in Noida

    Best institute for 3d Animation and Multimedia

    Best institute for 3d Animation Course training Classes in Noida- webtrackker Is providing the 3d Animation and Multimedia training in noida with 100% placement supports. for more call - 8802820025.

    3D Animation Training in Noida

    Company Address:

    Webtrackker Technology

    C- 67, Sector- 63, Noida

    Phone: 01204330760, 8802820025

    Email: info@webtrackker.com

    Website: http://webtrackker.com/Best-institute-3dAnimation-Multimedia-Course-training-Classes-in-Noida.php

    ReplyDelete
  9. Thanks For Sharing The Information The information Shared Is Very valuable Please keep updating us Time Just Went On reading The article Python Online Course AWS Online Course Devops Online Course DataScience Online Course

    ReplyDelete
  10. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai

    ReplyDelete
  11. I am really thankful for posting such useful information. It really made me understand lot of important concepts in the topic. Keep up the good work!
    Oracle Training in Chennai | Oracle Course in Chennai

    ReplyDelete
  12. Thanks for sharing great info with us.

    I wanted to write a little comment to support you and wish you a good continuation All the best for all your blogging efforts.Your good knowledge and kindness in playing with all the pieces were very useful.
    Python classes in Pune

    ReplyDelete

  13. It was really a wonderful article and I was really impressed by reading this blog. We are giving all software Courses such as Data science, big data, hadoop, R programming, python and many other course. big data training in bangalore is one of the reputed training institute in bangalore. They give professional and real time training for all students.

    ReplyDelete


  14. Great post.I really liked you article,your writing style is simply awesome with useful information. Best python certification course in Bangalore is offering Python training with 100% Placement assistance.Get certification under certified experts

    ReplyDelete
  15. Such a very well and helpful post..
    Thanks for sharing with us,
    We are again come on your website,
    Thanks and good day,
    Please visit our site,
    buylogo

    ReplyDelete
  16. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job,Keep it up.

    Try Our Evil Spirit Removal Expert In Toronto Services and Get All the benefits of it in your life, we make All your Personal problems solved in just minutes.

    ReplyDelete
  17. Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work
    Python Training in Chennai

    Python Training in Velachery

    Python Training in Tambaram

    Python Training in Porur

    Python Training in Omr
    Python Training in Annanagar


    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!Software Testing Training in Chennai

    Software Testing Training in Velachery

    Software Testing Training in Tambaram

    Software Testing Training in Porur

    Software Testing Training in Omr

    Software Testing Training in Annanagar

    ReplyDelete
  20. DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

    Good to learn about DevOps at this time.

    DevOps Training in Chennai

    DevOps Course in Chennai

    ReplyDelete
  21. Communication is a two way process. If done properly, it gives excellent result. Thus opting for the best Integrated Marketing Communication Course on Talentedge is wise. To know more visit:

    ReplyDelete
  22. Glad to visit this blog, really helpful. Gathered lots of information and waiting to see more updates.
    RPA Training in Chennai
    RPA Training Online
    RPA Course in Coimbatore

    ReplyDelete
  23. "Many regards to the blogger! I found your posts to be very helpful. They gave me a lot of inspiration and knowledge. Thank you for the helpful details. Continue your wonderful effort! eager to read more from you in the future."
    Regards,
    Software Testing Course

    ReplyDelete