Forum Discussion

technigirl74's avatar
technigirl74
Occasional Contributor
6 years ago
Solved

New here - need some help with a Groovy script.

Hi!

 

I've just started with SoapUI and Groovy scripting.  I can write code, but have never really worked with Java before (I'm more of a Python and C++ gal).  

 

I'm trying to write a Project level setup script that will utilize an existing test case that I have.  Basically, all I want to do is run this particular test case as a project setup script.  I've attached a picture of the test case setup.

 

To summarize, I need to grab the value of the property that is returned in the DataSource step, and then use said value in the test case that follows it (just as would happen if I were simply running the test case from the GUI).  I have the following code:

 

// get TestCase
def tc = testRunner.testCase.testSuite.project.testSuites["Basic Operations"].testCases["Get and Clone Scenario"]

 

//get simulation_id from data source

def sim_id = content.expand( '${Get Model ID#simulation_id}' )
log.info "Project level model simulation ID = $sim_id"

 

// set model clone properties
tc.setPropertyValue("id", "sim_id")

 

// run test synchronously
def runner = tc.run( null, false )

 

// log the results
log.info "Status: $runner.status, time taken for TestCase was: $runner.timeTaken ms"

 

I get the following error:

Caused by: groovy.lang.MissingPropertyException: No such property: testRunner for class: Script6

 

I also have a hard time reading Java tracebacks and am not sure exactly what line this error is happening in, though I'm guessing it's in the "tc.setPropertyValue" line.

 

I am obviously missing something but have no idea what.  Any help would be much appreciated!  Thanks!

 

 

 

 

  • nmrao's avatar
    nmrao
    6 years ago

    "project" object is directly accessible. Hope you can use it to get the right test. 

    See right top corner of the screen for the other objects which are available.

     

5 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Why do you need the test case in setup script? it is any way gong to be run right?

    By the way testRunner object is not available in project level setup script.
  • sanj's avatar
    sanj
    Super Contributor

    Here is a snippet of code that I have to run the test

    def project = testRunner.testCase.testSuite.project
    def testsuite= testRunner.testCase.testSuite
    tc = testsuite.getTestCaseByName("Templates")
    def testStep = tc.testSteps['Upsell -Bi']
    //def testStep = testRunner.testCase.testSteps['24HRRequestTest']
    def status = testRunner.status
    log.info("status : ${status}")

    def result= testStep.run(testRunner,context).getStatus().toString()

     

  • technigirl74's avatar
    technigirl74
    Occasional Contributor

    nmrao ah, that may explain it then, if the testRunner isn't available in a project level script.

     

    This test suite functions as a test yes, but it also is a procedure that I need to run as setup/teardown, and multiple times throughout my testing process.  

     

    If testRunner won't work, is there another way to run this in the project setup?

    • nmrao's avatar
      nmrao
      Champion Level 3

      "project" object is directly accessible. Hope you can use it to get the right test. 

      See right top corner of the screen for the other objects which are available.

       

  • technigirl74's avatar
    technigirl74
    Occasional Contributor

    I found a way to do it using the "project" object.  Thank you so much!