Forum Discussion

Arah's avatar
Arah
Occasional Contributor
3 years ago

Running Another TestCases, looping through Properties (getValues &SetValues) - Groovy Script

Hello,

how can I get all of the properties (it shouldn’t matter if there are only 2 or 100 on the list) with values from TestStep “LIST” from TestCase S_TC_Addition and set them on the TestStep “LIST” in TestCase M_TC_Add, and then, get all properties and values from TestStep “EXIT” in TestCase M_TC_Add and set them on the TestStep “EXIT” in TestCase S_TC_Addition, in groovy script (in this case EXECUTION_Addition)?

At the moment I have this (which only gets and sets properties that I've manually indicated "FirstValue", "SecondValue"):

 

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.wsdl.testcase.*
import com.eviware.soapui.model.testsuite.*

//Locating TestCase in different project
def projectName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("PROJECT_NAME")
def testSuitetName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("TEST_SUITE_NAME")
def testCaseName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("TEST_CASE_NAME")

//Getting only two properties from the "LIST" TestStep in S_TC_Addition TestCase
def firstNumber = testRunner.testCase.getTestStepByName("LIST").getPropertyValue("FirstValue")
def secondNumber = testRunner.testCase.getTestStepByName("LIST").getPropertyValue("SecondValue");

//Setting only two properties on the "LIST" TestStep in M_TC_Add TestCase
def passFirst = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("FirstValue", firstNumber);
def passSecond = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("SecondValue", secondNumber);

//Running TestCase in different project
testCaseToRun = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).testSuites[testSuitetName].testCases[testCaseName]
testCaseToRun.run(null,false)

//Getting one property from the "EXIT" TestStep in M_TC_Add TestCase
def getAdditionResult = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("EXIT").getPropertyValue("additionResult");

//Setting only one property on the "EXIT" TestStep in S_TC_Addition TestCase
testRunner.testCase.testSteps["EXIT"].setPropertyValue( "additionResult", getAdditionResult);

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Confusing description. Even diagram shows the unending loop.

     

    Suggestions:

    - Every test case should be independent. However, you have dependency between projects. Redesign your tests.

    - By the way, please avoid using "workspace" which will limit your automation as testrunner does not understand workspace.

    • Arah's avatar
      Arah
      Occasional Contributor

      Hey,

       

      about the independency of every TestCase, at work we use that kind of thing, so i was trying to recreate it (I do not have access to script that does this and all other things)

       

      this is what I wanted to achieve

       

      //Get all properties from current TestCase's TestStep "LIST" and transfer them to indicated TestCase in code above, and set them in TestStep "LIST"
      def ListProperties = testRunner.testCase.getTestStepByName("LIST").getPropertyList()
      ListProperties.each{ lp->
          passPropertiesToList = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("${lp.getName()}", "${lp.getValue()}");
      }
      
      //Get all properties from current TestCase and transfer them to indicated TestCase in code above
      def exitProperties = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("EXIT").getPropertyList()
      exitProperties.each{ ep->
          passPropertiesToExit =  testRunner.testCase.testSteps["EXIT"].setPropertyValue("${ep.getName()}", "${ep.getValue()}");
      }

       

       

      Is there other way to run differentTestCase, than using .workspace?