2
votes

I have 50+ tests in my current SoapUI workspace. I need to add a new project level parameter on all of these tests. Is there a way I can do this using the groovy console within SoapUI?

For example :

  testRunner.testCase.testSuite.project.setPropertyValue( "SuperMan",("SuperMan"));

I can run this to create a property within the current working project. Is there a way I can create this under all projects on my current workspace?

Thanks in advance.

2

2 Answers

3
votes

Yes, We can do this but it's little tricky.

Way to do this:

  1. Create a empty generic project in soapui, Add empty testsuite, add Empty testcase
  2. In test case Add a groovy script step
  3. Now paste this groovy code

    for(project in com.eviware.soapui.SoapUI.workspace.projectList) {    
     if(project.open && project.name != testRunner.testCase.testSuite.project.name){
           project.setPropertyValue( "TestProperty","TestValue");    
     }    
    }
    

Run the groovy step, you will get property added at Project level.

Please mark this as correct response if this solve your problem.

3
votes

Using your testRunner access you simply need one level more workspace. From here you can access projects map and iterate over each project adding the property:

testRunner.testCase.testSuite.project.workspace.projects.each{ key, proj ->
    proj.setPropertyValue('superman','superman')
}

This code doesn't add the property on closed projects in workspace but not fails accessing it.

Alternatively as @Rao suggest on his comment it's possible to use default it object iterator and access the value instead of defining key, proj -> on each:

testRunner.testCase.testSuite.project.workspace.projects.each{ 
    it.value.setPropertyValue('superman','superman')
}

I prefer the first approach for clarity.

Hope it helps,