Monday, October 11, 2010

How to automate flash chart using Sahi?

Recently we faced the challenge of automating tests for application using fusion charts. FusionCharts v3 helps you create animated & interactive charts for web & enterprise applications. In the application that we were testing, these came embedded in web pages using plain HTML and without using FusionCharts JavaScript class.

Our team’s objective was to test content of the flash chart. This flash chart was a stackarea chart with trending information.
We tried recognizing these charts with Sahi Controller but it got identified as a DIV tag.
And the only identification available was something like _div("ch57").



Here is what we did: We studied the HTML rendered and studied the content of EMBED tag.
When using HTML embedding for FLASH CHARTS, all variables to the chart are passed using FlashVars variable. This is the variable which holds the chart XML data.

REFERENCE - Flashvars takes various parameters as given in the Flash Chart documentation - http://www.fusioncharts.com/docs/ [Embedding Charts Using OBJECT or EMBED Tags].

For developing a sahi script that validates data content of the flash chart we developed following alogrithm.

(1) Navigate to test application where the flash chart is rendered
(2) Recognise the EMBED object using html-id.
(3) Read the tag attribute by the name flashvars
_call (document.getElementsByTagName("embed"))[0].getAttribute("flashvars");
(4) Build an XML object
(5) Validate data of interest by parsing XML

Best way to validate data of interest is to read the XML file at runtime from the application under test and log the datasets to a XML/CSV file. Depending on the business scenario tester can frame the base xml/CSV that is expected. One can then just do a simple file comparison.