Tuesday, August 19, 2008

Taking FunFX to the next level

Hi everybody

FunFX have been needing a facelift for a while now. It works, but there are aspects of FunFX that bearly works.

Aslak Hellesøy, a colleague from BEKK and creator of many fantastic Ruby applications, has taken the initiative to help me improve FunFX.

The bad thing about this facelift will be that there will be some changes in the way test scripts are written, so some rewriting will be necessary.

The first thing we have done is to base FunFX on Watir. This will make it simpler to get going with FunFX and alot of functionality is allready in place.

In the current version, all ruby classes of the Flex objects are created at runtime and in memory. This has made it difficult to begin using FunFX due to bad documentation. In the next version, these classes will be created on file, so that there will be a nice rdoc explaining these classes making it easier to use.

We have also changed to git instead of subversion, so it will be possible to create own versions, that we can merge.

I will write more about the upcomming FunFX during development. For now it is possible to find the new FunFX source at github.com. But notice that it is still early in development.

Hope you will use the new version!

Friday, July 11, 2008

Use the new Flex 3 components like AdvancedDatagrid

Hi

I just recently (yesterday) needed to test a advanced datagrid. I have just tested it as a regular datagrid for the moment. I have not been able to release a fix for this, so I write about it here instead, since I am going on a holiday now for the next 2 weeks.

To be able to utilize the advanceddatagrid you need to include a new file to the Flex project automation_dmv.swc. But with this file included the FunFX version out fails. But with a quick fix this will not be a problem.

Ilkka Kudjoi have made a fix, which is located http://dpaste.com/62646/. His fix makes FunFX only care about automationchildren. I used to only care for automationchildren, but changed it for a while back, but do not remember that for the moment.

So try it if you would like. But will release a new version i agust.

Have good summer!

Monday, June 23, 2008

Automation.swc locks application

Hi, I had a strange problem at work last week. The problem was when I added automation.swc and automation_agent.swc to a new project I am working on, all controls was lokced. I was not able to click on any objects. But as soon as I removed the swc files, everything worked great.

I did not have the time to take a closer look at the problem until today. And searched flexcoders (a great group by the way for information about Flex and Actionscript), to see if anyone else been through the same thing. And what do you know :-) At this post, I got to this site.

The problem seems to be that if you have an invisible container of some sort that overlaps other containers, that container will steal all the focus from any other container.

The solution to this problem is to add an eventlistener to the stage to be able to locate the container. And when you have discovered the container, add mouseEnabled="false" to it. Then everything should be working!

Thursday, June 12, 2008

Use FunFX together with Watir

Usually Flex applications uses a regular HTML pages for authentication or by other support. When this is the case, FunFX alone is not able to get to the Flex part. In these situations you can use the excellent tool Watir.

To make Watir work together with FunFX you do the same setup as usually with FunFX, but you also require watir, and attaches Watir to the browser FunFX started. With the example below I use the the title of the page to make Watir understand what browser to choose.

@ie = Funfx.instance@ie.start(true)
@ie.speed = 1
@ie.goto("http://localhost/flexapplication.html", "flexapplication")
$browser = Watir::IE.attach(:title, "PageTitle")


When you have done this, both the FunFX instance and the Watir instance is able to control the browser. But one thing you should watch out for is that when FunFX enter the Flex application, it must set the flex object again, so either if you use FunFX to navigate to the Flex application, you can define the flex object in the goto statement. Or you can use the setFlexObject method.

@ie.goto("www.google.com", nil)
$browser.text_field(:name, "q").set "pickaxe"
$browser.button(:name, "btnG").click
@ie.goto("http://localhost/flexapplication.html", "flexapplication")
@ie.button("buttonName").click


@ie.set_flex_object("flexapplication")

Tuesday, April 15, 2008

FunFX 0.0.4 Released

Hi, have been a while now, sorry about that. But now thanks to Neil Curzon, Bill Torla and Mario Sanchez a new version is available. This version has added a patch that makes it possible to access different browsers with in the tests, to look at different sessions.

It is now also possible to use FunFX together with Watir. It was difficult before, due to FunFX's lack of ability to hook onto other browser windows.

It is also now possible to select a row in a datagrid by index instead of text. It still uses the item_renderer option, but if you give a integer into it that is within the grids row count it chooses row by index.

Let me know how things work.

Monday, March 10, 2008

Finding the right element in a combobox

This post might be usefull not only for a combobox but all other list type of controls.

You have maybe found a better solution than this yourself, but I would like to show you a simple (maybe not the best) way to find specific item in a combobox. As you maybe know or have experienced Flex does only draw what you see and hence an item you do not see in the combobox is not possible to select. Due to this you will have to scroll the elements to make it visible.

I played around a couple of minutes and just created this while loop that scrolls all the items, and picks out the item with the itemrenderer "12"


@ie.combo_box("cbTest").open
num_rows = @ie.combo_box("cbTest").num_rows
position = 0
while(position <= num_rows)
@ie.combo_box("cbTest").scroll(:position => position)
begin
@ie.combo_box("cbTest").select(:item_renderer => "12")
position = num_rows + 1
rescue
position += 1
end
end


Support for this might be built into the FunFX framework, that it searches like that automatically, or what do you think?

Friday, February 22, 2008

FunFX and custom components


Hi, I have for a while now been supposed build a custom component with custom events and post how to to this here.

I am eventually finshed an example of how to create a custom component, which is not possible to act upon with the regular actions from FunFX.

(By the way, I followed this tutorial, Create custom component Flex, it is for QTP, but are in many ways the same way to create a custom component for FunFX.

Thanks alot to Jarek for pointing out the problem I had. I used the wrong variable in the call to the super class' constructor. I used a couple of hours yesterday banging my head in to the wall. But after the help from Jarek everything fell into place.

It is actually very easy to implement an custom component, and use it with FunFX. What you need to do is 4 steps:

1. Create the custom component

2. Create the custom event

3. Create the delegate that extends for instance UIComponentAutomationImpl

4. Add the component to the AutomationGenericEnv.xml file


(Does not need to do them in that order)


Create the custom component


I chose to create a simple component listing different buttons, which could easily be done with a repeater, but that is not the point. I wanted to find out and hopefully share my findings with you guys, that haven't tried it yet. What I wanted to do was to implement my own event, so that I could use the itemrenderer tag in the event to make the buttons be pushed.

Below is the code for the custom component. It just extends from a existing component and overrides the necessary methods like, createChildren etc. What is important to notice here is that you need to add you children, that you want to reach into the _renderers so that they can be used by the delagate as automationChildren. The top event sentence makes it possible for the delegate to replay that customevent, which I will create after this.


[Event(name="itemClick", type="event.CustomItemClickEvent")]
public class CustomComponent extends VBox
{
private var _dataProvider:Array;
private var _renderers:Array = [];
private var _itemRenderer:IFactory = new ClassFactory(Button);

public function CustomComponent()
{
super();
}

override protected function createChildren():void{
super.createChildren();
for(var i:int=0; i<_dataProvider.length; i++){
var inst:UIComponent = _itemRenderer.newInstance();
inst.addEventListener(MouseEvent.CLICK, itemClickHandler);
this.addChild(inst);
_renderers.push(inst);

Button(inst).label = _dataProvider[i];
}
invalidateSize();
invalidateDisplayList();
}
//You must also implement an itemClickHandler, for the buttons, but that is nothing special
}


Create the custom event


To be able to click on the button, I need to create a custom event that makes this happen. This event holds a button which is the type of item the custom component is holding. It is probably possible to do this a bit more generic, but this was just to understand how things works.


public class CustomItemClickEvent extends Event
{
public var itemRenderer:Button;
public static const ITEM_CLICK:String = "itemClick";

public function CustomItemClickEvent(type:String){
super(type, bubbles, cancelable);
}
}


Create the delegate


The delegate must be included to the application project that uses the custom component. I chose to build an swc of the delegate and add it as the FUnFXAdapter.swc file.

Below is the code from the delegate. It is important to use the [Mixin] attribute, as this forces the delegate's init methd to be run when your application starts. The numAutomationChild and getAutomationChild methods you will have to implement concerning how your custom component added items to the renders array. Here you can do what you want.


[Mixin]
public class CustomComponentDelegate extends UIComponentAutomationImpl
{
public static function init(root:DisplayObject):void
{
Automation.registerDelegateClass(CustomComponent, CustomComponentDelegate);
}

private var comp:CustomComponent;
public function CustomComponentDelegate(component:CustomComponent)
{
super(component);
comp = component;
}

override public function get numAutomationChildren():int
{
var renderers:Array = comp.getItemRenderers();
if(renderers != null)
return renderers.length;
else return 0;
}

override public function getAutomationChildAt(index:int):IAutomationObject
{
var renderers:Array = comp.getItemRenderers();
if(renderers == null) return null;
if(index >= 0 && index < renderers.length)
return renderers[index];
else
return null;
}

override public function replayAutomatableEvent(event:Event):Boolean
{
var help:IAutomationObjectHelper = Automation.automationObjectHelper;
if (event is CustomItemClickEvent)
{
var rEvent:CustomItemClickEvent = event as CustomItemClickEvent
help.replayClick(rEvent.itemRenderer);
(uiComponent as IInvalidating).validateNow();
return true;
}
else
return super.replayAutomatableEvent(event);
}


Add the component to the AutomationGenericEnv.xml file


When everything is created you can add the component to the AutomationGenericEnv.xml file. Below is what I added somewhere in the file below the Object (because it is based on inheritance and the file is parsed.)


<ClassInfo Name="CustomComponent" Extends="Object" SupportsTabularData="true">
<Implementation Class="CustomComponent"/>
<Events>
<Event Name="ItemClick">
<Implementation Class="customEvent::CustomItemClickEvent" Type="itemClick"/>
<Property Name="itemRenderer">
<PropertyType Type="String" />
</Property>
</Event>
</Events>
<Properties>
</Properties>
</ClassInfo>


Building a test application and writing a test


Now you are ready to write an application using the component and a test which interacts with the component.


<Application="" mx="http://www.adobe.com/2006/mxml" component="component.*">
<mx:VBox>
<component:CustomComponent="" id="cust" dataprovider="['Nr1','Nr2']"/>
</mx:VBox>
</mx:Application>



@ie.custom_component("cust").item_click(:item_renderer => "Nr2")



I hope this was helpfull, and possible to understand :-)

Do not forget to read the post about RSpec and Stories that I wrote just before this post. Thanks!