Forum Discussion

Finan's avatar
Finan
Frequent Contributor
13 years ago

Script does not work in soapUI 4.5

Hi,

Since soapUI pro 3.6 we've used a groovy script in the project.save script to clean our properties from obsolete values.

This script no longer works in soapUI pro 4.5 (tested in 4.0 and 3.6.1, and it works).

Can you provide a solution for this problem?

the script:

removeProjectProperties();

for(testSuite in project.testSuites){
testSuite = project.getTestSuiteByName(testSuite.key);
for(testCase in testSuite.testCases){
testCase = testSuite.getTestCaseByName(testCase.key);
if(testSuite.name.startsWith("Blocks")){ //Blocks testsuites contain reusable testfunctions, all testcase properties within these testsuites can be emptied
//clear testCase properties
int count = testCase.getPropertyCount();
for(int i = 0; i < count; i++){
propertie = testCase.getPropertyAt(i);
propertie.setValue("");
}
}
for(testStep in testCase.testSteps){
testStep = testCase.getTestStepByName(testStep.key);
if(testStep.class.toString().equals("class com.eviware.soapui.impl.wsdl.teststeps.WsdlRunTestCaseTestStep")){
int count = testStep.getPropertyCount();
for(int i = 0; i < count; i++){
propertie = testStep.getPropertyAt(i);
if(propertie.name.startsWith("out_")){
propertie.setValue("");
}
}
}
}
}
}

/*
Remove old project properties:
1.i=0 and will remain so
2.project.getPropertyCount will return a lower value for every execution, (removeProperty)
3.Ultimately getPropertyCount will return 0, exiting the function
*/
void removeProjectProperties(){
for(int i = 0;i<project.getPropertyCount();i){
project.removeProperty(project.getPropertyAt(i).name);
}
}
log.info "Project was cleared of obsolete data";


I get a java.lang.ArrayIndexOutOfBoundsException
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Does it say on which row the exception is occurring somewhere (e.g. soapUI log or error log)?

    Regards

    Henrik
    SmartBear Software
  • Finan's avatar
    Finan
    Frequent Contributor
    Thu Apr 12 13:57:22 CEST 2012:ERROR:java.lang.ArrayIndexOutOfBoundsException: -1
    java.lang.ArrayIndexOutOfBoundsException: -1
    at java.util.ArrayList.elementData(Unknown Source)
    at java.util.ArrayList.remove(Unknown Source)
    at com.eviware.soapui.model.environment.EnvironmentImpl.removeProperty(SourceFile:320)
    at com.eviware.soapui.model.environment.EnvironmentImpl.removePropertyByName(SourceFile:351)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro$InternalTestPropertyListener.propertyRemoved(SourceFile:786)
    at com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder.firePropertyRemoved(XmlBeansPropertiesTestPropertyHolder.java:136)
    at com.eviware.soapui.impl.wsdl.support.XmlBeansPropertiesTestPropertyHolder.removeProperty(XmlBeansPropertiesTestPropertyHolder.java:219)
    at com.eviware.soapui.impl.wsdl.AbstractTestPropertyHolderWsdlModelItem.removeProperty(AbstractTestPropertyHolderWsdlModelItem.java:124)
    at com.eviware.soapui.impl.wsdl.MutableTestPropertyHolder$removeProperty.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at Script1.removeProperties(Script1.groovy:37) ==> project.removeProperty(project.getPropertyAt(i).name);
    at Script1.run(Script1.groovy:27)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89)
    at com.eviware.soapui.impl.wsdl.WsdlProject.runBeforeSaveScript(WsdlProject.java:1519)
    at com.eviware.soapui.impl.wsdl.WsdlProject.beforeSave(WsdlProject.java:911)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro.beforeSave(SourceFile:370)
    at com.eviware.soapui.impl.wsdl.WsdlProject.saveIn(WsdlProject.java:768)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro.saveIn(SourceFile:363)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro.save(SourceFile:438)
    at com.eviware.soapui.impl.wsdl.actions.project.SaveProjectAction.perform(SaveProjectAction.java:42)
    at com.eviware.soapui.impl.wsdl.actions.project.SaveProjectAction.perform(SaveProjectAction.java:28)
    at com.eviware.soapui.support.action.swing.SwingActionDelegate.actionPerformed(SwingActionDelegate.java:89)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    On a side node, the log also shows the following error:
    Thu Apr 12 13:57:23 CEST 2012:WARN:Failed to delete temporary project file; C:\Workspace\Testen\###\soapUI\project-temp-3894800989267663626.xml
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    Hmm...It should not work like that. Removing properties should be done like this:


    def propertyNames = project.getPropertyNames()
    for(name in propertyNames){
    project.removeProperty(name);
    }


    Hope this helps,
    robert
    /Smartbear
  • Finan's avatar
    Finan
    Frequent Contributor
    it didn't help.
    After some testing with 4.5, it seems that every delete action results in this error.

    Reproduction:
    1. create new project. (test)
    2. add new project property (a)
    3. delete property via the button that has as onmouseover "Removes the selected property from the property list"
    4. check error log.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    I used this script to add properties to project ( groovy test step ):


    def testCase = context.testCase
    def project = testCase.testSuite.project
    def n = Integer.parseInt(testCase.properties["N"].value)

    for( int i = 0; i < n ; i++ ) {
    project.setPropertyValue("N${i}".toString(), i.toString())
    }


    and this to remove them all ( project save script, I think you put your script there too ):

    def project = context.testCase.testSuite.project
    def propertyNames = project.getPropertyNames()

    for( name in propertyNames )
    project.removeProperty(name)


    This is working without any issues. Can tell me what soapUI you are using( I know it is 4.5, please check Help->About )?

    robert
  • Finan's avatar
    Finan
    Frequent Contributor
    soapUI Pro 4.5.0, copyright (C) 2007-2012 smartbear.com http://www.soapui.org | http://smartbear.com Build [internal], Build Date 2012/03/26 16:19

    If I execute your (robert) script in the project Save Script, I receive the following error:

    Fri May 11 08:10:31 CEST 2012:ERROR:An error occured [Cannot get property 'testSuite' on null object], see error log for details


    (Error log)
    Fri May 11 08:10:00 CEST 2012:ERROR:java.lang.NullPointerException: Cannot get property 'testSuite' on null object
    java.lang.NullPointerException: Cannot get property 'testSuite' on null object
    at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:56)
    at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:156)
    at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:44)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
    at Script1.run(Script1.groovy:1)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89)
    at com.eviware.soapui.impl.wsdl.WsdlProject.runBeforeSaveScript(WsdlProject.java:1519)
    at com.eviware.soapui.impl.wsdl.WsdlProject.beforeSave(WsdlProject.java:911)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro.beforeSave(SourceFile:370)
    at com.eviware.soapui.impl.wsdl.WsdlProject.saveIn(WsdlProject.java:768)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro.saveIn(SourceFile:363)
    at com.eviware.soapui.impl.wsdl.WsdlProjectPro.save(SourceFile:438)
    at com.eviware.soapui.impl.wsdl.actions.project.SaveProjectAction.perform(SaveProjectAction.java:42)
    at com.eviware.soapui.impl.wsdl.actions.project.SaveProjectAction.perform(SaveProjectAction.java:28)
    at com.eviware.soapui.support.action.swing.SwingActionDelegate.actionPerformed(SwingActionDelegate.java:89)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.AbstractButton.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    I'm sorry I forgot to write first script is used in Groovy test step in test case, second in Save Script on project level.
    So, this error is expected.

    robert
    /Smartbear