Saturday, December 22, 2007

FormItem problem

Hi!

I just recently got a notice on my last post from Neil that when using FunFX a null pointer exception is thrown when any form item's label in a form is null as shown in the first listing. Neil pointed out that it was also happening when the label was set to an empty string.

<mx:form>
<mx:formitem label="Form Label">
<mx:label id="lLabel"/>
</mx:formitem>
<mx:formitem>
<mx:textinput id="tTextInput"/>
</mx:formitem>
</mx:form>


Neil pointed out that it was something to do with the FunFX and FormItemAutomationImpl interaction. And that one need to set all the form items labels to a non empty string. And that using whitespaces as label affects the layout. He suggested a nice workaround until a fix with the FormItemAutomationImpl is done. And that is to set the label width to 0.

<mx:form>
<mx:formitem label="Form Label">
<mx:label id="lLabel"/>
</mx:formitem>
<mx:formitem label="" labelWidth="0">
<mx:textinput id="tTextInput"/>
</mx:formitem>
</mx:form>


I have created the error for my own, and the reason for the error is as Neil said. The FunFX uses the automation framework from Adobe to create string id of the display objects that it interacts with. And this method in the FormItemAutomationImpl.as as displayed in the following listing. When the label of the formitem is null, there is no check that will prevent the method to call the length method of the label, which might be null.

private function getItemAutomationName(child:IAutomationObject):String
{
//Have cut down the method
result = (label.length != 0 ? label + ":" + child.automationName : child.automationName);
// More in the real method
}

I have not yet been able to check wether it is possible to just add a null pointyer check in the method. But this will probably implie a change in th corresponding method that creates an object from the string id.

I hope this will help people in the same situation as Neil. And I will see if it can be fixed. But so long you will need to do as Neil suggested and set the labelWidth of the form item to zero.

Thanks alot Neil, for this valuable tip and solution!

10 comments:

Ziki said...

Hi Peter,
thanks for the post !
I bumped with another problem, when i tried to test a TabNavigator as in the following example, thought the click on the panel will be enough, but apparently i cant click on object that is not yet visible.
The Ruby code is below the sample.
<mx:Panel
title="TabNavigator Container Example"
height="90%" width="90%"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

<mx:TabNavigator id="tn"
width="100%" height="100%">
<!-- Define each panel using a VBox container. -->

<mx:VBox id="vb1" label="Panel 1">
<mx:Label text="TabNavigator container panel 1"/>
</mx:VBox>

<mx:VBox id="vb2" label="Panel 2">
<mx:Label text="TabNavigator container panel 2"/>
</mx:VBox>
</mx:TabNavigator>
</mx:Panel>
Ruby code:
@ie.tab_navigator("tn").panel("vb2").click
any help will be appreciated,
thanks

Peter Motzfeldt said...

Hi Ziki!

I am sorry about the lack of documentation about all the API calls. I have ment to create a better documentation for a while but the time as gone by.

But with the tab navigator you must use the change method. And in you case you must write:

@ie.tab_navigator("tn").change(:related_object => "Panel 2")

The related object is the label or automationName of the tab that you want to switch to.

Hope this helps!

Ziki said...

Yes! thank you!
now i understand the "related_object" usage :)
the AutomationGenericEnv.xml is really helps if you understand the Flex framework, but the "related_object" is not there... also there is no clear example about tabs, by the way FunFx works pretty good on custom components - cool!! :)

Peter Motzfeldt said...

Thank you very much, I am happy it works. There are alot of things I have not yet been able to test. So let me know if there are anything that does not work.

You can also use the mailing list at http://rubyforge.org/projects/funfx/ if you want to.

Have a happy holiday!

Ziki said...
This comment has been removed by the author.
Ziki said...

Hi, i'll do that, thanks..
another thing,
if you will add to the previous TabNavigator example to VBox id="vb2" an automationName="autoVb" and will use the :related_object like you shown in the sample:
@ie.tab_navigator("tn").change(:related_object => "autoVb")
it don't work in this example (or i missing something), but with the Label tag its work.
The problem is when your label is something like:
label={LabelProperties.getLabel(LabelProperties.TAB_LABEL)}
where the label taken from language file. In that case better way is to use the automationName tag, but somehow it doesn't work.
I'll be glad to any help
Thanks.

Bindiya Mansharamani said...

hey ziki,
If the tabbed navigator is added to the VBox then you just have to navigate to the vbox using @ie.VBox("vb2").change(:related_object => "TabbedNavigator")


let me know if i miss understood your question

Vjay said...

Hi Peter, I am facing one issue while testing flash component on the web...
I am using Ruby1.8.6.patch26
I am using Microsoft IE.I have installed Watir & Funfx gems.

I have generated .swf from my source code & I have merged it in web application.

With help of Watir I am able to login to website & reach upto Flash page.
But when I am trying to click any flash component using Funfx syntax,I am getting this error

1) Error:

test_OrgChart(Login):

NoMethodError: private method `split' called for nil:NilClass

D:/Ruby/lib/ruby/gems/1.8/gems/FunFX-0.0.4/lib/flex.rb:33:in `method_missing'

D:/Documents and Settings/vshinde/workspace10/OrgChartHit/login.rb:38:in `test_OrgChart'


1 tests, 0 assertions, 0 failures, 1 errors


I have verified the component id's & names.I am attaching my code hereby.
Any help will be appreciated.
Thanks in advance.

Regards,
Vijay

Vjay said...

the code is as follows..

require 'test/unit'
require 'funfx'
require 'watir'
require 'rubygems'
require 'win32ole'


class Login < Test::Unit::TestCase


def setup

@ie = Funfx.instance
@ie.start(true)
@ie.speed = 1
@ie.goto("http://vshinde:8180/Saba/Web/Main", nil)

$browser = Watir::IE.attach(:title, "Saba") # Attaches Watir to the browser
$browser.frame(:name, 'SabaMain').text_field(:id, 'id1004').set "uthree"
$browser.frame(:name, 'SabaMain').text_field(:id, 'id1005').set "welcome"
$browser.frame(:name, 'SabaMain').link(:text, 'Log In').click


end

def test_OrgChart




@ie.goto("http://vshinde:8180/Saba/Web_wdk/Main/common/orgchart/orgChartPopup.rdf?showModeling=false&contextVal=enduser&callback=callback1094#","SABA")
sleep(2)
#assert_not_nil(@ie.CheckBox("showAlternateReport"))
@ie.CheckBox("showAlternateReports").click

puts 'look for handle'
end



end

Peter Motzfeldt said...

Hi

A stupid quiestion from me, but do you have compiled your Flex application with the correct automation files and the funfxadapter.swc file?