0

I am facing an issue where if I am changing my 1st request to POST/GET then all other request is turn by same.

So I have created a new project for all of my GET request.

Can now using groovy, can I run any testcase or teststep?

I am testing for Rest API

I am using below code then getting error like:-

def tCase = testRunner.testCase.testSuite.testCases["Request_for_Product_Import"]

def tStep = tCase.testSteps["Api - Chekcing_Request_Product_Import"]

TestStep.run( tCase,  tStep)

java.lang.NullPointerException: Cannot get property 'testSteps' on null object error at line: 3

My this request -> "Api - Chekcing_Request_Product_Import" is present on different project

There is one more dependency my 1st groovy script is taking an data from first request and I need to pass that value to my 2nd script which is present on another project that is :- Api - Chekcing_Request_Product_Import

For that I am using below code:-

def valueFromPreviousResponse = <replace your value here>
context.testCase.testSuite.setPropertyValue('REQUEST_ID', valueFromPreviousResponse)

I have added above code in a groove file name as :- Getrequest(Please refer the image)

Then I am the value in another GET request as below:-

https://mywebsite/api/api_jobs/get_response?request_id=${#TestSuite#REQUEST_ID}

My project structure is as below image:-

enter image description here

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • Possible duplicate of [If a request is changed to POST, then SoapUI changing all other requests into POST method](http://stackoverflow.com/questions/34786729/if-a-request-is-changed-to-post-then-soapui-changing-all-other-requests-into-po) – SiKing Jan 16 '16 at 19:51

2 Answers2

1

I have found ways to achieve above issue

For Get Request create a new project and and then create a GET request. Now right click on request -> Clone TestStep and then select your needed project and click on Ok.

Now the another thing is how to send values which is come from 1st request. For that you can set that value to global properties of SOAP-UI and then can retrieve the same using groovy script

To set the value to global properties use below code:-

def valueFromPreviousResponse = slurperresponse.products.request_id
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "Request_Dynamic_ID", valueFromPreviousResponse )

To read the value from global properties use below code:-

def Globalrequest = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "Request_Dynamic_ID" )
log.info(Globalrequest)

Run the testcase of any project in SOAP-UI using below code

//get test case from other project or from the same one
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("REST Project 2")
testSuite = project.getTestSuiteByName("PIM2_TestSuite");
testCase = testSuite.getTestCaseByName("Request_for_Product_Import");

//set properties if you need
//testRunner.testCase.setPropertyValue(property_name, property_value);
//testRunner.testCase.setPropertyValue(another_property_name, another_property_value);

// run test case
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

You can use

TestStep.run(TestCaseRunner testRunner, TestCaseRunContext testRunContext)

to run a test step from anywhere in SoapUI

user1207289
  • 3,060
  • 6
  • 30
  • 66
  • Thanks for the answer .. But can you please explain this ... where I need to specify the name of teststep.... .. Can you please give me a example so that I can utilize your above code – Shubham Jain Jan 15 '16 at 05:40
  • @Shubham Jain seems like your `tStep` is in different project. Have a look at [this](http://stackoverflow.com/questions/22047403/is-it-possible-from-groovy-script-test-step-to-run-specific-test-steps-in-other). I think that's what you want. – user1207289 Jan 15 '16 at 17:35