Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Jubula » Custom action (How to add a new action to an out of box tester class)
Custom action [message #1039562] Fri, 12 April 2013 09:48 Go to next message
Gabor Nagy is currently offline Gabor NagyFriend
Messages: 9
Registered: July 2009
Location: Hungary
Junior Member
Hi,

I am using Jubula 2.0.0.2013281048 (nightly build) installed into Eclipse 4.2

I would like to add a new action to SWT.Label. For example to check the tooltipText. I know it is possible to check it with the "checkProperty" but this example is just to make my problem more easy to explain.
I have already created a new tester class for Composite with action which is working fine.
This is what I did in the label case to add a new action:

1. I added this to the ComponentConfiguration.xml
<toolkitComponent type="org.eclipse.swt.widgets.Label2" visible="true">
		<realizes>guidancer.abstract.SwtLabel</realizes>
		<testerClass>org.eclipse.jubula.rc.swt.tester.MyLabelTester</testerClass>
		<componentClass name="org.eclipse.swt.widgets.Label" />
		<action name="M8CompSystem.CheckTooltip" >
			<method>rcCheckTooltip</method>
			<param name="M8CompSystem.TooltipText">
				<type>java.lang.String</type>
			</param>
			<param name="CompSystem.Operator">
				<type>java.lang.String</type>
				<defaultValue>equals</defaultValue>
				<valueSet>
					<element name="CompSystem.Equals" value="equals"/>
					<element name="CompSystem.NotEquals" value="not equals"/>
					<element name="CompSystem.MatchesRegExp" value="matches"/>
					<element name="CompSystem.SimpleMatch" value="simple match"/>
				</valueSet>
			</param>
		</action>
	</toolkitComponent>


2. Created MyLabelTester which extends the org.eclipse.jubula.rc.common.tester.LabelTester

3. Added
public void rcCheckTooltip(String expectedTooltip,String operator) {...}

4. Implemented IAdapterFactory
public class MyExtensionAdapterFactory implements IAdapterFactory
{

    @Override
    public Class[] getSupportedClasses()
    {
        return new Class[]{Label.class};
    }

    @Override
    public Object getAdapter(Class targetedClass,Object objectToAdapt)
    {
        
        if (targetedClass.isAssignableFrom(IComponent.class))
        {
            if (objectToAdapt instanceof Label)
            {
                return new ControlAdapter(objectToAdapt);
            }
        }
        return null;
    }
}


5. When I want to add a new test for the Label "New Test Step" I can select the my toolkit component which names the SWT.Label to Label2 and from the "Action" combo I can select my action to check the tooltip.
But when I run the test I got an error message "Operation not supperted by the selected toolkit."

For me it seems that not my MyLabelTest class is used but the original LabelTester.
I looked at the org.eclipse.jubula.rc.common.adaptable.AdapterFactoryRegistry.getAdapter(). If this is the code which decides which adapter to use then I think always the first one will be given back. For the same class more adapters are mapped and probably my M8ExtensionAdapterFactory is at the end of the list.

  public Object getAdapter(Class targetAdapterClass,Object objectToAdapt)
    {
        Collection registeredFactories = null;
        Class superClass = objectToAdapt.getClass();
        while ((registeredFactories == null) && (superClass != Object.class))
        {
            registeredFactories = (Collection) this.m_registrationMap.get(superClass);
            superClass = superClass.getSuperclass();
        }
        if (registeredFactories == null)
        {
            return null;
        }

        Iterator iterator = registeredFactories.iterator();
        while (iterator.hasNext())
        {
            IAdapterFactory adapterFactory = (IAdapterFactory) iterator.next();
            Object object = adapterFactory.getAdapter(targetAdapterClass,objectToAdapt);

            if (object != null)
            {
                return object;
            }
        }
        return null;
    }


Is there a way to use MyExtensionAdapterFactory with the SWT.Label?

Thanks in advance
Gabor
Re: Custom action [message #1041819 is a reply to message #1039562] Mon, 15 April 2013 16:06 Go to previous messageGo to next message
Carlos Feal is currently offline Carlos FealFriend
Messages: 5
Registered: March 2013
Junior Member
Hi,

Try to make next changes in your ComponentConfiguration.xml:

- Change <realizes>guidancer.abstract.SwtLabel</realizes> to <extends>org.eclipse.swt.widgets.Label</extends>
- Remove <componentClass> tag. It is not necessary if you specify the extension.
- Add to i18n.properties the reference to your extension:
org.eclipse.swt.widgets.Label = <SWT_Label_Extension> (the name you want)

In jubula client, when you add a new test step, there should be a component called "<SWT_Label_Extension>". Use this new component (your extension of swt Label, with all the actions of swt Label plus your new actions).

Also, when I have implemented my extensions with Jubula 2.0 I found some problems with the fragments. See the following thread: http://dev.eclipse.org/mhonarc/lists/jubula-dev/msg00287.html
Re: Custom action [message #1042244 is a reply to message #1041819] Tue, 16 April 2013 07:05 Go to previous message
Gabor Nagy is currently offline Gabor NagyFriend
Messages: 9
Registered: July 2009
Location: Hungary
Junior Member
Thank you very much. This was the missing part from my example you just advised me to try out. It works fine now. I also had problem with the RSA creating the fragment and yes deleting the RSA file solved it.
Thanks again, you made my day Smile
Gabor

[Updated on: Tue, 16 April 2013 07:11]

Report message to a moderator

Previous Topic:Download older version of jubula
Next Topic:Click at graphic component in Jubula 2.0
Goto Forum:
  


Current Time: Tue Oct 08 00:41:19 GMT 2024

Powered by FUDForum. Page generated in 0.03475 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top