3
votes

I'm using SoapUI Pro. The SoapUI site says I should be able to set context variables and get those values at any time during the test's execution. In the help it says:

A common usage scenario is for looping or keeping track of progress by saving the corresponding counters and collections to the context and using them to control flow as required.

I can't get this to work if I'm using the out-of-the-box 'Run TestCase' test step. The called test doesn't seem to get passed the context information.

Here's a very basic example. In my originating test I put in some Groovy script that says this:

context.PassedInTest = "Is this passed in?" log.info(context.PassedInTest)

Then in my called test, I have another Groovy script that says this:

log.info(context.PassedInTest)

Upon execution of the test, the log displays: "Is this passed in?" for the originating test, but then the log displays null for the called test:

Mon Oct 27 12:59:45 EDT 2014:INFO:Is this passed in?
Mon Oct 27 12:59:56 EDT 2014:INFO:null

Is there a way to pass in the context if using the out-of-the-box 'Run TestCase' test step in SoapUI (i.e. not using Groovy script)? What am I doing wrong?

1
Each test case has a different context. - SiKing

1 Answers

0
votes

I managed to get this working, but I can't say if it's hacky or not...

Consider following project structure:

Project
|-CallingTestSuite
| |-CallingTestCase
|   |-TestSteps
|     |-LocalScript (Groovy TestStep)
|     |-RemoteScript (Run TestCase TestStep)
|-CalledTestsuite
  |-CalledTestCase
    |-TestSteps
      |-CalledScript (Groovy TestStep)

Now, you cannot pass (at least I didn't find a way) context of LocalScript to CalledScript. You can, however, access the content of LocalScript from CalledScript.

LocalScript:

context.PassedInTest = "Is this passed in?"
log.info(context.PassedInTest)

CalledScript:

if (context.getProperty("#CallingTestRunContext#") != null){
    log.info(context.getProperty("#CallingTestRunContext#").PassedInTest);
}

Keep in mind that it needs to be executed as CallingTestSuite, CallingTestCase, or Project, otherwise the target context won't be available.