Component find and not fail

4 views
Skip to first unread message

OlivierD

unread,
May 2, 2009, 12:45:06 PM5/2/09
to easytesting
Hello,

Is there a way to look for a component and not fail if it doesn't
exist.
Basically, I want to look for a Button, if it exist I want to click
on it. If not do nothing.

Thanks in advance,

Olivier

Alex Ruiz

unread,
May 2, 2009, 3:15:24 PM5/2/09
to easyt...@googlegroups.com
Hi Olivier,

ComponentFinder has a method 'findAll' that returns a list of components that match search criteria specified in a ComponentMatcher (Monday's release includes an overloaded version that takes a GenericComponentMatcher). If no components were found, the returned list will be empty without throwing exceptions.

Use the method 'finder' in a FEST robot to obtain a ComponentFinder.

Regards,
-Alex

OlivierD

unread,
May 2, 2009, 4:35:29 PM5/2/09
to easytesting
Hi Alex,

I am doing
Collection<Component> found = robot.finder().findAll(new
ComponentMatcher() {

public boolean matches(Component c) {
if (c instanceof JButton) {
if(((JButton) c).getName() != null){
if(((JButton) c).getName().compareTo
("MY_BUTTON") == 0){
return true;
}
}
}
return false;
}
});


But when I run the test on xvfb

I got an exceptioin :
Test class should have public zero-argument constructor

java.lang.Exception: Test class should have public zero-argument
constructor
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
Caused by: java.lang.NoSuchMethodException: unit.tests.InventairesTest
$1.()
at java.lang.Class.getConstructor0(Class.java:2706)
at java.lang.Class.getConstructor(Class.java:1657)

Thanks,

Olivier

On May 2, 9:15 pm, Alex Ruiz <alex.ruiz...@gmail.com> wrote:
> Hi Olivier,
>
> ComponentFinder has a method 'findAll' that returns a list of components
> that match search criteria specified in a ComponentMatcher (Monday's release
> includes an overloaded version that takes a GenericComponentMatcher). If no
> components were found, the returned list will be empty without throwing
> exceptions.
>
> Use the method 'finder' in a FEST robot to obtain a ComponentFinder.
>
> Regards,
> -Alex
>

Alex Ruiz

unread,
May 4, 2009, 9:15:20 AM5/4/09
to easyt...@googlegroups.com
Hi Olivier,

It seems that the problem is that your test case does not have a default constructor.

Cheers,
-Alex
Reply all
Reply to author
Forward
0 new messages