cancel
Showing results for 
Search instead for 
Did you mean: 

SoapUI - How to use the context variable set in test suite at the test case

New Contributor

SoapUI - How to use the context variable set in test suite at the test case

Hello!

Is there any way I can use the context variable set in test suite at the test case.

 

Thanks

7 REPLIES 7
Community Hero

Re: SoapUI - How to use the context variable set in test suite at the test case

How about this?

context.testCase.testSuite.setPropertyValue('name', 'value')


Regards,
Rao.
New Contributor

Re: SoapUI - How to use the context variable set in test suite at the test case

I want to pass a variable that is defined in test suite with value as an Object and use in the subsequent test cases.

For eg. My test suite has set up script which defines a context variable as follows
context.testSuiteVariable = new HelloWorld()

I want to use this context.testSuiteVariable in my test case. Any idea how to achieve this?
Highlighted
Community Hero

Re: SoapUI - How to use the context variable set in test suite at the test case

@sumeet0420 

 

You can simply use

context.testSuiteVariable

 

If you want an example, here you go:

Selection_034.png



Regards,
Rao.
Community Leader

Re: SoapUI - How to use the context variable set in test suite at the test case

Hi @sumeet0420 ,

 

In your TestSuite you can assign value to context variable by below:

context.setProperty("varName", varValue);

And in your TestCase, you can use the value by below:

log.info context.varName

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
New Contributor

Re: SoapUI - How to use the context variable set in test suite at the test case

Hi,

This will not work as TestSuite context is different from TestCase object.

Test Case Context is an instance of TestCaseRunContext while Test Suite Context is an instance of TestSuiteRunContext.
Community Hero

Re: SoapUI - How to use the context variable set in test suite at the test case

I could not related your response to which reply.

Can you provide more details?
Have you tried the given solution before saying this will not work?


Regards,
Rao.
Community Hero

Re: SoapUI - How to use the context variable set in test suite at the test case

When you run the test suite, the contents of the TestSuiteRunContext is put into each TestCaseRunContext (both classes are essentially just LinkedHashMaps).

 

So it should work as Rao described, but ONLY when the test suite is actually being run. When you run individual test cases or steps, the values won't be passed in (even if you have previously run the test suite or test suite set up script previously). See attached.

 

For a solution that lets you run single test cases and steps manually, you could use Properties on the test suite instead, as these are more permanent. The downside is that Properties can only be strings.

New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors
Top Kudoed Posts