How to read and use SoapUI API for non Dev people?

Originally posted by codehausss on November 04, 2015

Hello,

i don’t have any background in development especially in java.

I would like to learn how to read and use SoapUI API from SoapUI API docs (http://www.soapui.org/apidocs/index.html?overview-summary.html)

something like testRunner, context, messageExchange.

how do i know which method or which variable i can use for i.e context variable, testRunner variable

usually i see someone write like

context.expand

or something like

testRunner.testCase.testSuite

where i can get this information?

I would like to understand how people know they can user expand in the context variable etc

many thx

Originally posted by rupert_anderson on November 04, 2015

Hi,

This obviously isn’t a complete answer, just my personal view and before learning about SoapUI, Groovy scripting and writing a book about it, I had a lot of Java / API / frameworks experience, but I would say the online help docs can be quite useful and was where I started e.g.

http://www.soapui.org/scripting---properties/tips---tricks.html

Basically I learned by example, created lots of Groovy Test Steps and had a good hack about to learn how to extract / insert data to and from objects, requests and responses…

Also, there are various blogs etc and was one book at the time.

I never did the certification, not sure how much scripting is in that, possibly someone else could say?

Any specific examples / explanataions of variables / scripts, then let me know…

Cheers,

Rupert

Originally posted by nmrao on November 04, 2015

Though the question is too generic, but it is near to my heart as I was in the same situation when I started using it.
Initially, started searching on the net. Sometimes, lucky to get the info what was needed then and sometimes may not.
On one fine day, had happened to watch the video https://www.youtube.com/watch?v=92WEfVJPJDQ
And started more thirst from there.
Hope you too get the benefit out of it.

Originally posted by codehausss on November 06, 2015

Hi Rupert, nmrao

many thanks for your reply, also watching the youtube vid.

actually my biggest confusion is related with the path, class and available method.

Like in above youtube vid for 2nd webinar, they write

println workspace

.
I am trying the same syntax in groovy test step and got error no such property workspace for class

i know in teststep groovy there is variable log, context, testRunner,
still i don’t know the method i can use for each of them

i am trying

log.info context.metaClass.methods*.name

got error can not get property methods

i am trying

log.info testRunner.metaClass.methods*.name

got below result

[equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait, cancel, fail, getLog, getReason, getRunContext, getStartTime, getStatus, getTestRunnable, getTimeTaken, isRunning, setRunContext, start, waitUntilFinished, getResults, getRunContext, getTestCase, gotoStep, gotoStepByName, runTestStep, runTestStepByName, setMockRunContext]

still i am confuse, usually when i am googling some script, people write like this

testRunner.testCase.testSuite...

from above metaClass result i can’t find after testRunner i can write testRunner.testCase.
how does people know about this?

Originally posted by nmrao on November 07, 2015

In the video, it is explained how one can explore the soapUI API.

Below is groovy script test step.

If you notice above, below variables are accessible:

log, context, testRunner.

Now, if you want to know details about testRunner variable, then just have the following statement in the groovy step and execute it, so that you would know what is the type of this variable

log.info testRunner

You may see below output

Sun Nov 08 00:10:13 IST 2015:INFO:com.eviware.soapui.impl.wsdl.panels.support.MockTestRunner@43810d51

Now open the class MockTestRunner in soapui’s api docs where you can see the allowed methods on testRunner say getTestCase().

As you mentioned, testRunner.testCase and testRunner.getTestCase() are same. testRunner.testCase is groovified version(ignores explict get and paranthesis). Other one is java way.

So, like above, you can find any object’s class and look into api docs to get the methods.

And similarly, if you see the project load script, test suite setup, teardown and test case setup and teardown (all of them or groovy type ) different variables available and are mentioned like how we see for groovy step.

Originally posted by codehausss on November 07, 2015

Thanks nmrao, very clear explanation, i am started to understand how to read the API document.

would like to ask you agan:

  1. Only “get” followed by “parantheses” i can ommit from method name, is it correct?

  2. I am able to access another teststep inside another test suite using

    log.info testRunner.testCase.testSuite.project.workspace.getProjectByName("myProject").testSuites["yourTestSuite"].testCases["TestCase 1"].testSteps["delete"].testRequest.responseContentAsXml
    

    is there any possibility to shortened above script?

  3. I am able to run another teststep inside another test suite using

    log.info testRunner.testCase.testSuite.project.workspace.getProjectByName("myProject").testSuites["yourTestSuite"].testCases["TestCase 1"].testSteps["delete"].run(testRunner, context)
    

    but i can not understand what is the meaning from (TestCaseRunner runner, TestCaseRunContext runContext) inside run method.
    What is the function of testRunner and context inside this method?

regards,

Originally posted by nmrao on November 08, 2015

#1. Yes.

Like, context.testCase.name and context.getTestCase().getName() are same and here there are no arguments involved*.*

Similarly set also, however, it mostly may contain some argument.

How to set a test case property

But it will be little different if there are arguments to be passed for either set and get methods.

context.testCase.setPropertyValue('PROPERTY_NAME','PROPERTY_VALUE')

Can also be expressed as

context.testCase.properties['PROPERTY_NAME'].value = 'PROPERTY_VALUE'

How to get a test case property

context.testCase.getPropertyValue('PROPERTY_NAME')

or

context.testCase.properties['PROPERTY_NAME'].value

At least, above are some variants of set / and get methods while using groovified.

  1. Gald know that.

If you want to access artifacts from other test suite, one must at least have project object(by accessing it successive parents). Here, you went one level ahead i.e., workspace which is not required.

Get the project object :

def currentProject = context.testCase.testSuite.project

Then use currentProject later for all references if you dont want to use it long.

currentProject.testSuites["yourTestSuite"].testCases["TestCase 1"].testSteps["delete"].testRequest.responseContentAsXml

#3 one is also same as above.

Originally posted by codehausss on November 12, 2015

Many thanks nmrao for you explanation

if my understanding are correct, context and testRunner have same meaning?

when i should use context and when i should use testRunner?

hopefully you’re not get boring with my question :slight_smile:

Originally posted by nmrao on November 12, 2015

Context is defined at project, test suite, and test case levels. So object can vary depending upon where it is being accessed. And similarly TestRunner.

To your question, both are not same, testRunner is member variable of context object. Applies to all levels.

Originally posted by codehausss on November 28, 2015

thanks nmrao for very long explanation, got better understanding now on API and context & testRunner variable :slight_smile:

Originally posted by nmrao on November 28, 2015

Glad to know and closing the topic.

Originally posted by infomaven on March 28, 2024

This breakdown and explanation was very helpful.

Originally posted by infomaven on March 31, 2024

I enjoyed reading through this thread. This is a classic approach that can work for learning any kind of software language; not just Groovy, and the participants showed professionalism and respect for each other. The Forum met its purpose!