FlexMonkey 5.1.1 – Automation Spark DataGrid with Custom GridItemRenderers

1 03 2012

In my previous blog posts I have discussed how to actually get flexmonkey to automate a spark DataGrid, but the problem was, if you had any custom GridItemRenderers inside of it, suddenly it didn’t know how to properly automate them. I made a simple spark data grid and filled it with data, and made a custom item renderer that renders a red box for ‘false’ and a green box for ‘true’, pretty simple:

So what happens if you click on one of the rows while recording in FlexMonkey (the AIR app)?

Notice how it essentially copies down the entire row of data, and puts asterisks around the actual row you clicked? In the first one, we clicked the 3rd row, in the “price” column, so it put asterisks around the the $350 ┬áto let the automation framework know that that was the one that was clicked. But, in the second one, there is nothing there for the “popular” column, its just an empty string! if you try to replay this now, it won’t work, since it doesn’t know how to represent the custom GridItemRenderer we are using. The other columns work fine since they don’t use a custom renderer, so they use a built in class DefaultGridItemRenderer.

So how do we get our code for our custom GridItemRenderer to identify itself correctly to the automation framework? I did a lot of tracing in what goes on behind the scenes since, as per usual, there is almost no documentation on the FlexMonkey website. It turns out, there is a property that is inherited from UIComponent called automationValue, that basically represents the ‘value’ that can be used to identify this GridItemRenderer in the automation framework. In our case, since our custom GridItemRenderer’s data is only a boolean, it makes sense to just have it return the boolean state of the row’s “popular” field.

So we just override the getter for the automationValue property:

override public function get automationValue():Array {

return [theState];

}

and when we run the app again, and try recording the value with the FlexMonkey AIR app:

Now it recognizes the GridItemRenderer, and if you play the events back, its able to correctly find what row/column you selected and play it back.

I have posted the example code for this here, if you are interested in taking a look at it. It contains the FlexMonkey source code, the libraries that are needed to build said source code, and the automation libraries that adobe provides the source for. HOWEVER, you still need to link to one more swc file (which adobe doesn’t give the source for), you do this by right clicking the project -> properties -> flex build path -> add swc, and this swc is located in your FlexSDK folder. For me, its located in:

/…/flexsdk/flex_sdk_4.5.1.21328/frameworks/libs/automation/automation_agent.swc

once you link that, you should be good. Let me know if you have any questions.


Actions

Information

2 responses

30 03 2012
Tom Lee

Just wanted to say keep up the good work – I’m currently in the process of FlexMonkey-ing an app with a lot of custom datagrids, so I’m finding your work helpful. Thanks for putting this out there!

31 03 2012
polygon89

you are welcome! It seems that they arn’t really stepping up to the plate to support later versions of flex, and i’m still having problems where the env xml file is missing methods, but any thing i find out i’ll post here!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: