cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with GUI in test step plugin

SOLVED
New Contributor

Problem with GUI in test step plugin

Hello,

 

I try make SoapUI test step plugin but I have a problem with GUI. According to information here I created new test step project using Maven. Three class has been generated: 

1. ActionGroups.java

2. MyTestStep.java

3. PluginConfig.java

According to information here and here I added new class MyTestStepPanelBuilder to add gui to my test step:

package com.mycompany;

import com.eviware.soapui.impl.EmptyPanelBuilder;
import com.eviware.soapui.model.ModelItem;
import com.eviware.soapui.plugins.auto.PluginPanelBuilder;
import com.eviware.soapui.ui.desktop.DesktopPanel;

@PluginPanelBuilder(targetModelItem = MyTestStep.class)
public class MyTestStepPanelBuilder extends EmptyPanelBuilder {

@Override
public DesktopPanel buildDesktopPanel( ModelItem modelItem )
{
return new MyTestStepDesktopPanel( (MyTestStep)modelItem );
}

@Override
public boolean hasDesktopPanel()
{
return true;
}
}

 

 And MyTestStepDesktopPanel.java

 

package com.mycompany;

import com.eviware.soapui.ui.support.ModelItemDesktopPanel;

public class MyTestStepDesktopPanel extends ModelItemDesktopPanel<MyTestStep>
{

public MyTestStepDesktopPanel ( MyTestStep modelItem )
{
super( modelItem );
}

}

 

When I add new test step, everything looks good: new test step is created, GUI is shown.

 

1.PNG

 

But when closed the window and try reopen by double click on "My TestStep" the window doesn't appear.
What I do wrong that the window can't open ? I have included this simple project as an attachment. In previous plugin architecture I always create plugins based on this and everything was ok, but in new plugin architecture I can't resolve that problem.

Maybe anybody had the same problem and know answers on my question ?

 

2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Problem with GUI in test step plugin

Hi,

 

What happens when you double-click on an item in the Navigator is that the default action in the popup menu gets executed. The problem is that the Action group that gets associated with your test step (and hence the popup menu) does not contain this action.

 

In later versions of SoapUI – i.e. in Ready! API – you would add a new action group using the annotation @ActionGroup, but this is not available in SoapUI 5.1.

 

What you need to do is to use the SoapUI Action registry to register an instance of WsdlTestStepSoapUIActionGroup with the name "MyTestStepActions" (which is the simple name of your Test step class + the suffix "Actions"). There are two ways you can do that in SoapUI 5.1:

 

1) Use the method SoapUIActionRegistry.addConfig() to load an actions.xml containing this Action group configuration.

2) Using Java reflection to call the package protected method in SoapUIActionRegistry.addActionGroup().

 

I chose the second solution in the attached version of your PluginConfig class, adding this code to an overridden initialize() method that will be called when the plugin is loaded:

 

@Override
public void initialize() {
try {
Method addActionGroupMethod = SoapUIActionRegistry.class.getDeclaredMethod("addActionGroup", SoapUIActionGroup.class,
String.class);
addActionGroupMethod.setAccessible(true);
WsdlTestStepSoapUIActionGroup testStepActionGroup = new WsdlTestStepSoapUIActionGroup("MyTestStepActions",
"MyTestStepActions");
addActionGroupMethod.invoke(SoapUI.getActionRegistry(), testStepActionGroup, testStepActionGroup.getId());
} catch (Exception e) {
UISupport.showErrorMessage("Couldn't add action group for MyTestStep");
e.printStackTrace();
}
}

 

Kind regards,

Manne, Ready! API/SoapUI developer

View solution in original post

Staff

Re: Problem with GUI in test step plugin

The problem with the icon is actually a problem about resource loading. In Ready API this works out of the box, but to make it work in SoapUI you have to do a workaround.

 

In order to make it work you have to register the plugin's classloader. This can be  done in the initialize method in your PluginConfig.

 

com.eviware.soapui.support.UISupport.addResourceClassLoader(getClass().getClassLoader());

Adding this to your plugin should make the icon show in the menu and the toolbar also.

Regards
Joel Jonsson
SmartBear Stockholm Developer

View solution in original post

3 REPLIES 3

Re: Problem with GUI in test step plugin

Hi,

 

What happens when you double-click on an item in the Navigator is that the default action in the popup menu gets executed. The problem is that the Action group that gets associated with your test step (and hence the popup menu) does not contain this action.

 

In later versions of SoapUI – i.e. in Ready! API – you would add a new action group using the annotation @ActionGroup, but this is not available in SoapUI 5.1.

 

What you need to do is to use the SoapUI Action registry to register an instance of WsdlTestStepSoapUIActionGroup with the name "MyTestStepActions" (which is the simple name of your Test step class + the suffix "Actions"). There are two ways you can do that in SoapUI 5.1:

 

1) Use the method SoapUIActionRegistry.addConfig() to load an actions.xml containing this Action group configuration.

2) Using Java reflection to call the package protected method in SoapUIActionRegistry.addActionGroup().

 

I chose the second solution in the attached version of your PluginConfig class, adding this code to an overridden initialize() method that will be called when the plugin is loaded:

 

@Override
public void initialize() {
try {
Method addActionGroupMethod = SoapUIActionRegistry.class.getDeclaredMethod("addActionGroup", SoapUIActionGroup.class,
String.class);
addActionGroupMethod.setAccessible(true);
WsdlTestStepSoapUIActionGroup testStepActionGroup = new WsdlTestStepSoapUIActionGroup("MyTestStepActions",
"MyTestStepActions");
addActionGroupMethod.invoke(SoapUI.getActionRegistry(), testStepActionGroup, testStepActionGroup.getId());
} catch (Exception e) {
UISupport.showErrorMessage("Couldn't add action group for MyTestStep");
e.printStackTrace();
}
}

 

Kind regards,

Manne, Ready! API/SoapUI developer

View solution in original post

New Contributor

Re: Problem with GUI in test step plugin

Big thanks for your help!

 

I have one small additional question for you about icon in test step.

How path in iconPath should I set in @PluginTestStep

I have icon in the same place where classes, set iconPath to "/icon.png" and the icon doesn't appear in SoapUI.

 

When I set icon by this piece of code in constructor:

 

if (!forLoadTest) {
    setIcon(new ImageIcon(getClass().getResource("/icon.png")));
}

the icon appear but only in created test step, not in menu, test case toolbar etc.

 

I have included this simple project as an attachment.

Staff

Re: Problem with GUI in test step plugin

The problem with the icon is actually a problem about resource loading. In Ready API this works out of the box, but to make it work in SoapUI you have to do a workaround.

 

In order to make it work you have to register the plugin's classloader. This can be  done in the initialize method in your PluginConfig.

 

com.eviware.soapui.support.UISupport.addResourceClassLoader(getClass().getClassLoader());

Adding this to your plugin should make the icon show in the menu and the toolbar also.

Regards
Joel Jonsson
SmartBear Stockholm Developer

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Building with the Collaborator API

Help Documenation
The Collaborator API is a JSON-RPC API that lets you integrate with Collaborator 9.0 and above. For more information about how the API works, check out the API description here:


Sample Plugins
For an example of an add-in that uses the API, take a look at the Microsoft Word Add-in for Collaborator:


We list all the great plugins our network has already built on this page on the SmartBear website.