Testing your Flex app with new FunFX
A few weeks ago I’ve started to dig in to new funfx gem to transform our old FunFx code and get benefit of new features that new FunFX is providing. The main reasons for moving to new code are:
- Support for Firefox, so now we can run tests even on Linux boxes
- Support for AdvancedDatagrid
- Much better way to find components with :id and :automationName
- Based on Watir so we can test also IE if needed
- Visual recorder and component finder
Installation
You can install new funfx with just running on console command gem install funfx or you can download source code from GitHub. The funfx gem is dependent on Watir specific gem. Based on platform or preferences install either Watir (Win XP, Vista), SafariWatir (Mac OS X) or FireWatir (all platforms). NOTE: With FireWatir you’ll need to install Firefox Extension!
Installation Examples
- Using gems on Mac OS X
1 2 3 | sudo gem uninstall FunFX sudo gem install funfx sudo gem install safariwatir |
- Using source code (you’ll need Git installed)
1 2 3 4 5 6 7 8 9 | sudo gem uninstall FunFX git clone git://github.com/peternic/funfx.git cd flex ./build.sh cd .. cd gem/ rake gem rake install_gem sudo gem install safariwatir |
FunFX interface changes
Changing speed of your FunFX run
Old version was using class attribute on FunFX object like this:
1 | FunFX.speed = 0.5 # half of second |
New version has different class attribute name:
1 | FunFX.fire_pause = 0.5 |
FunFX language/DSL changes
Basic components didn’t change, but arguments you’re passing changed from Hash-like style to simple arguments or vice versa.
- Finding component
For example to find component you can now use more than one identificator like :id, :automationName and so on.
Old style to find component:
1 | @browser.text_area('myname') |
New style:
1 | @browser.text_area(:id => 'myname') |
- Getting number of rows from DataGrid
Old style (as a result you will get concatenated string by comma):
1 2 | @browser.data_grid('myname').tabular_data(:start => 0, :end => 2) => '1,Timothy Ferris,user' |
New style (as a result you will get array of column values for each row):
1 2 | @browser.data_grid('myname').values(0,2) => [['1','Timmothy Ferris','user']] |
- How to find all supported methods and their arguments?
To find the right number of arguments and their meaning have a lot at elements.rb file or generate RDoc.
- Methods returning boolean
All methods returning boolean value now requires you to write question mark at the end of the method name.
Old style:
1 | @browser.check_box(:id => 'myname').selected |
New style:
1 | @browser.check_box(:id => 'myname').selected? |
- No CamelCase in method names
Old FunFX supported both styles for method calls; CamelCase and classic ruby style with underscore. New FunFX forces you to use only classic ruby style with underscore.
Old style:
1 | @browser.check_box(:id => 'myname').currentState |
New style:
1 | @browser.check_box(:id => 'myname').current_state |
Observations
Pros:
- Code is much cleaner and is promising much stable way for writing FunFX tests.
- Multiple browser’s and platforms support.
- Easy way to find components.
Cons:
- Recorder is not always useful in copy/paste scenario
- Visual component finder is not able to find itemRenderers inside DataGrid (you have to go through tree manually)
- Not much of documentation
Links and resources:
Old FunFX site: http://funfx.rubyforge.org/
Author and main contributor to FunFX: http://peternic.blogspot.com/
New FunFX GitHub repository: http://github.com/peternic/funfx/tree/master
RubyForget site: http://funfx.rubyforge.org/
Bug/Issue tracking: http://bekkopen.lighthouseapp.com/projects/20367-funfx/
Google Group: http://groups.google.com/group/funfx?pli=1
Comments(15)
Great writeup Ladislav!
A couple of comments:
Instead of looking at AutoQuick.xml dor finding available methods, it’s better to look at http://github.com/peternic/funfx/blob/6060855a03c79adbf399a04591cb12f115e07eca/gem/lib/funfx/flex/elements.rb – or generate RDoc and look at the API docs.
As for documentation – the Wiki is open for anyone to edit and contribute content.
Aslak
And of course – FunFX works particularly well with Cucumber!
Great comments! Thanks
Hi Aslak
I tried using funfx (0.2.2) to automate flex application on firefox. I followed the steps mentioned in http://github.com/peternic/funfx/blob/6060855a03c79adbf399a04591cb12f115e07eca/gem/website/tutorial.html
I am able to go to the page containing my Flex application. After that I get reference to the Flex application (id, name is correct) but it does not help in
looking up Flex elements with Automation IDs.
example: I tried following
@flex.button(:id => “login”).click()
but it did not clicked the button
Is there anything I am missing to add?
I downloaded the LoginFormExample application from a website http://svn.riaforge.org/flexamples/trunk/(Subversion).
I wrote a FUNFX script to automate the testing process. Script is as follows
require ’spec_helper’
describe “LoginFormExample” do
before do
browser.goto(“file:///C:/lrn/MarchFlexLrn/login/bin-debug/LoginFormExample.html”)
@flex = browser.flex_app(‘LoginFormExample’, ‘LoginFormExample’)
@flex.text_input({:id => ‘username’}).input(’skaranam’)
@flex.text_input({:id => ‘password’}).input(‘password’)
end
it “should click around” do
end
end
I’m able to launch Browser, but I’m not able to see username and password values entering .Can you please help us..
i am followed Installing the FireWatir on http://wiki.openqa.org/display/WTR/FireWatir Installation and create testcase like “http://wiki.openqa.org/display/WTR/FireWatir Example Script”
but when i run test case i said “undefined method `flex_app’ for # (NoMethodError)”
does anyone have any idea why?
Make sure you use
require ‘funfx/browser/firewatir’
and not
require ‘firewatir’
what is the proper way to assign the flex app?
I am having issues with the first command after I have done the assignment.
require ‘rubygems’
require ‘funfx’
require ‘funfx/browser/firewatir’
FunFX.fire_pause = 0.2
BROWSER = FireWatir::Firefox.new
BROWSER.goto(“localhost:8080/portal”)
BROWSER.text_field(:name, “j_username”).set(“username”)
BROWSER.text_field(:name, “j_password”).set(“password”)
BROWSER.button(:src, “/portal/public/img/but-login.gif”).click
@flex = BROWSER.flex_app(‘main’, ‘main’)
sleep(20)
23 @flex.LinkButton({:id => “logout”}).click
/usr/lib/ruby/gems/1.8/gems/firewatir-1.6.2/lib/firewatir/MozillaBaseElement.rb:967:in `assert_exists’: Unable to locate element, using nil (Watir::Exception::UnknownObjectException)
from /usr/lib/ruby/gems/1.8/gems/firewatir-1.6.2/lib/firewatir/MozillaBaseElement.rb:1403:in `method_missing’
from flex_1.rb:23
I have used automationName as well as id. I seem to not be setting the reference correct to the flex app. Any help would be appreciated.
Hello Mr Ladislav Martincik,
After reading the review about FunFx i have downloaded it to try it out.
After i installed the tool(ruby 1.8.6 with funfx 0.2.2 in windows Xp) i didn’t see any tool that you have talked about in your review (Visual recorder and component finder).
If it is possible for you to tell me where are these tools, i googled and found nothing, or if then are a different download.
Sorry for any bad english.
TIA
Ricardo Fernandes
Can any one please help me in moving forward. I have the same above discussed problems. I have reached/ opened the flex application but I am unable to click the button. Below is the code I am using,
require ‘watir’
require ‘rubygems’
require ‘funfx’
require ‘funfx/browser/firewatir’
@ff = FireWatir::Firefox.new
@ff.goto(“http://localhost:8080/Myproject/bin-debug/Myproject.html”)
@flex = @ff.flex_app(‘Myproject’, ‘Myproject’)
@flex.button(:automationValue => ‘Click’).click
#@flex.button(:id => ‘Btn’).click
I have posted this problem in many blogs and I haven’t received any help till now. I got stuck with issue and not able to continue the automation. Any info regarding accesssing the objects in swf will greatly help me
Thanks,
Panni
Hi Peter/ Toolsmith,
Thanks for the software .. I have succeded in automating the sample application and is replaying the script without any errors. Actually I had problem with swc files inclusion paths … earlier they used to be at different locations and flex builder was unable to include them … I copied all of them in to a single folder and updated the additional arguments path in Flex compiler options .. and the FunFx started working automatically …!!
Thanks again !!
I have to now work on my client application
Thanks,
Panni
Hi I have a different problem now. The swf in the application I am trying to automate does not have application ID, it has only application name. Can any one please let me know how to assign ID to an swf ?
~ Panni
Hi,
I am using funfx 0.2.2 for both browsers IE and FF. I am trying to attach to the already open browser. For IE, it works well but for FF it gives error (If I am using firewatir 1.6.2).
On http://github.com/bret/watir/tree/master, there is new version of firewatir (1.6.5rc2) which has fixed this problem for automating firefox.
It does not work with funfx 0.2.2
I get following error :
uninitialized constant Element
I am trying to look for any changes that has taken place but still need your help!
Thanks,
Kaustubh
[...] Testing your Flex app with new FunFX | Ladislav Martincik – Personal website [...]
Hi Peter,
Thanks for this useful article. I’m trying to set up Cucumber to test a Flex application. I’ve got everything set up now but had a couple of questions:
1. Is FunFX still being developed or has it been superceded by something else now?
2. Is the application at the old FunFX site below still suitable to do some test work on? The old funfx (0.0.4) looks very different to the new one (0.2.2) and I’m concerned it may not work any more.
http://funfx.rubyforge.org/Flex/FlexObjectTest/FlexObjectTest.html
Thanks very much in advance,
Gordon