Forum Discussion

Kathryn_O_Malle's avatar
Kathryn_O_Malle
Contributor
16 years ago

Groovy version of "Run TestCase step" in SoapUI 3.5

Hi,

When adding a new step to a testcase, one of the options is "Run TestCase".

I need to be able to simulate the functionality of this in a Groovy Script step. I've been able to run a separate testcase in the same testsuite but I need to be able to do this with a testcase in a separate testsuite. How can I do this please???

Any help welcome...
Thanks
Adam Hall

NB: I've tried the code in http://www.eviware.com/forums/index.php?topic=3134.0 but I've not been able to get it to work for some reason...
NB: Via http://www.eviware.com/blogs/oleblog/?p=431 I've been able to do it for a testcase in the same testsuite

6 Replies

  • Hi!

    The code you referred to should work, ie

    testRunner.testCase.testSuite.project.testSuites[".."].testCases["..."].run( new StringToObjectMap(), false )

    how is this not working?

    regards!

    /Ole
    eviware.com
  • Hi,

    I've tried the following lines of code in a Groovy Script step:
    [tt:1af40w9t]def slaveTestCase = testCase.testSuite.project.getTestSuiteByName["TS:TEST_Slave"].testCases["TC:TEST_Called_This_TestCase_Slave"]
    def runner = slaveTestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), flase)[/tt:1af40w9t]

    When I execute this groovyscript teststep I get the following error message:
    [tt:1af40w9t]"groovy.lang.MissingPropertyException: No such property: testCase for class: Script9"[/tt:1af40w9t]

    I've also tried the following variation:
    [tt:1af40w9t]def slaveTestCase = testRunner.testCase.testSuite.project.getTestSuiteByName["TS:TEST_Slave"].testCases["TC:TEST_Called_This_TestCase_Slave"]
    def runner = slaveTestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), flase)[/tt:1af40w9t]

    When I execute this groovyscript teststep I get the following error message:
    [tt:1af40w9t]"groovy.lang.MissingPropertyException: No such property: getTestSuiteByName for class: com.eviware.soapui.impl.wsdl.WsdlProjectPro"...[/tt:1af40w9t]

    I'm pushing the boundaries of my soapui knowledge here so hopefully I'm making a beginners mistake...

    Thanks
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    In your variation try this

    def slaveTestCase = testRunner.testCase.testSuite.project.getTestSuiteByName("TS:TEST_Slave").getTestCaseByName("TC:TEST_Called_This_TestCase_Slave")

    or

    def slaveTestCase = testRunner.testCase.testSuite.project.testSuites["TS:TEST_Slave"].testCases["TC:TEST_Called_This_TestCase_Slave"]

    Square brackets when accessing like a Map, braces (parentheses) when using a method (get...).
  • Hi,

    Many thanks for that, it worked!

    It has generated a couple of extra questions on the topic...

    When executing the groovy script teststep directly in SoapUI I can see log.info messages from the controlling groovy script itself, but I don't see any of the log.info messages from the slave test case. Is there a way to do this?
    [I can see them when viewing the actual soapui.log file though...]

    After some googling I've also had the following variation which I've now been able to get to work using the fix from M McDonald...
    Option_Two
    [tt:1deolyml]def testCase = testRunner.testCase.testSuite.project.getTestSuiteByName("TS:TEST_Slave").getTestCaseByName("TC:TEST_Called_This_TestCase_Slave")
    def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
    def async = false
    testCase.run (properties, async)[/tt:1deolyml]

    I find Option_Two easier to read but...

    Though with Option_Two I'm not clear on how to pass or retreive parameters from TC:TEST_Called_This_TestCase_Slave. Is there an online manual (API, etc) that I've missed so far that will help?

    Many thanks...
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    It's strange you can't see the logging, I created 2 trivial test cases, one calling the other and I see logging from both when I run the calling test case.

    I think you could use this to get and set TestCase properties:


    [tt:2yw7fvek]testCase.setPropertyValue("exampleInputProp", "Hello")

    testCase.run (properties, async)

    def output = testCase.getPropertyValue("exampleOutputProp")[/tt:2yw7fvek]

    Would that suffice?