Forum Discussion

max1965's avatar
max1965
Contributor
13 years ago

Script to delete testsuite properties

In my project I have many testsuite and many testcase.

In each of them I put in the setup script the instructions to remove properties before the execution of the test and all works fine.

To better manage the changes in the script I made the following procedure.

For the testcase, I create a TestSuite with a teststep to clear the properties; follow what I do:

1) create a testSuite called Scripts
2) create a testCase called ClearTestSteps
3) create a groovy test step called Clear with the following instruction:

try {
def delete_properties_udb = context.expand( '${#Global#delete_properties_udb_tc}' )
if ( delete_properties_udb == "Y" )
{
def propertyNames = testRunner.testCase.getPropertyNames()
for(name in propertyNames){
if ( (!name.toString().startsWith("QC_")) & (!name.toString().startsWith("synced")) ){
testRunner.testCase.removeProperty(name);
}
}
}
} catch(e) {
log.error("An error occurred: " + e.toString());
}

In each testCase Setup Script I put the following lines:

testRunner.testCase.testSuite.project.testSuites["Scripts"].testCases["ClearTestSteps"].testSteps["Clear"].run(testRunner, context);

When I execute the testCase, the properties are correctly removed.

I try the same solution also for the testSuite:

1) into the Script testSuite, I create a testCase called ClearTestSuites
2) create a groovy test step called Clear with the following instruction:

try {
def delete_properties_udb = context.expand( '${#Global#delete_properties_udb_ts}' )
if ( delete_properties_udb == "Y" )
{
def propertyNames = testRunner.testCase.testSuite.getPropertyNames()
for(name in propertyNames){
if ( (!name.toString().startsWith("QC_")) ){
testRunner.testCase.testSuite.removeProperty(name);
}
}
}
} catch(e) {
log.error("An error occurred: " + e.toString());
}

In each testSuite Setup Script I put the following lines:

testRunner.testCase.testSuite.project.testSuites["Scripts"].testCases["ClearTestSuite"].testSteps["Clear"].run(testRunner, context);

When I execute the testSuite I have the following error:

Tue May 07 15:08:48 CEST 2013:ERROR:groovy.lang.MissingPropertyException: No such property: testRunner for class: Script1
groovy.lang.MissingPropertyException: No such property: testRunner for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at Script1.run(Script1.groovy:1)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
at com.eviware.soapui.impl.wsdl.WsdlTestSuite.runSetupScript(WsdlTestSuite.java:509)
at com.eviware.soapui.impl.wsdl.panels.testsuite.WsdlTestSuiteDesktopPanel$SetupScriptGroovyEditorModel$1.actionPerformed(WsdlTestSuiteDesktopPanel.java:428)
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.plaf.basic.BasicButtonListener.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.Window.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)

Someone can help me to fix the problem ?

1 Reply

  • brigadir's avatar
    brigadir
    Occasional Contributor
    Just adding this response as someone might need it in the future

    To clear all project testsuite testcase properties step values I use following script. It will loop through all your project active testsuites looking for testcases that contain "Properties" step and if it finds one. It will clear its properties and enables on it "discard values on save" feature.

    def testSuites = project.getTestSuiteList();

    for (testSuite in testSuites) {
    if (!testSuite.isDisabled()) {
    def testCases = testSuite.getTestCaseList();
    for (testCase in testCases) {
    def propertiesSteps = testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.WsdlPropertiesTestStep.class);
    for (step in propertiesSteps) {
    step.clearPropertyValues();
    step.setDiscardValuesOnSave(true);
    }
    }
    }
    }


    Add this to your project overview "Save Script" tab.