Forum Discussion

kkochubey's avatar
kkochubey
New Contributor
14 years ago

How to run test case from custom soapUI menu (extension)

Hi, just want to share simple groovy code (soapUI extension) that allows to run predefined test case from project current workspace.. by selecting soapUI menu. It is simple example based on original demo from soapUI site..

It was created by using free community edition Intellij Idea with complete groovy support

package com.my.soapui.extension

import com.eviware.soapui.model.ModelItem
import com.eviware.soapui.support.UISupport
import com.eviware.soapui.support.action.support.AbstractSoapUIAction

public class MyAction extends AbstractSoapUIAction

{

public MyAction()
{
super("My Action", "My action extension to soapUI");
}

public void perform(ModelItem target, Object param)
{
def workspace = com.eviware.soapui.SoapUI.workspace
def targetTree = target.name.toString()

for(def parentItem=target.getParent(); (parentItem); parentItem=parentItem.getParent()) {
targetTree = parentItem.toString() + "||" + targetTree
}

def myActionProject = workspace.getProjectByName("my-actions")

if (!(myActionProject)) {
UISupport.showInfoMessage("Could not find my-action project in workspace. Open my-action to run My Action extensions.");
return;
}

myActionProject = workspace.openProject(myActionProject)

def tc = myActionProject?.getTestSuiteByName("My Actions")?.getTestCaseByName("My Actions")
if (!(tc)) {
UISupport.showInfoMessage("Could not load [my-actions].[My Actions].[My Actions] test case");
return;
}

tc.setPropertyValue("targetTree",targetTree)
tc.setPropertyValue("targetClass",targetTree)
tc.setPropertyValue("targetName",targetTree)
tc.setPropertyValue("param",targetTree)

def runner = tc.run(null,false)
if (runner.results.size()==0) return

runner.results.each{ it ->
if(it.error) {
UISupport.showErrorMessage(it.toString());
}
}
}
}


It compiles into 6k jar file and can be saved in ...\soapUI-3.6.1\bin\ext\

It can be called called from soapUI test case popup menu (or F4) extended with my-action.xml

<?xml version="1.0" encoding="UTF-8"?>
<tns:soapui-actions xmlns:tns="http://eviware.com/soapui/config">
<!-- defined action -->
<tns:action id="MyAction" actionClass="com.my.soapui.extension.MyAction"/>
<tns:actionGroup id="WsdlTestCaseActions">
<tns:actionMapping actionId="MyAction" name="My Action" description="Run My Action" keyStroke="F4"/>
</tns:actionGroup>
</tns:soapui-actions>



So it runs [my-actions] project [My Actions] suite and [My Actions] test case if it is availbale in current workspace
My Actions test case gets 4 properties with name of test case where custom menu was selected. So you can add any steps to be executed based on input test case name.


It works fine in 3.6.1 free and pro versions