cancel
Showing results for 
Search instead for 
Did you mean: 

How to get Endpoint from the Request

SOLVED
Contributor

How to get Endpoint from the Request

I wanna to get full Endpoint from the request. I passing endpoints dynamically for each step that I need to record it.

I tried below options to get complete url (Constant one + dynamically passed) but its just giving me only the constant endpoint

1) def endpoint = (testRunner.testCase.testSteps["GET"].testRequest.response.rawResponseData)
new String(endpoint)

The Output is something like this - [B@7f0b1367

2) def endpoint = (testRunner.testCase.getTestStepByName("GET").getTestRequest().getResponse().getRawRequestData())

new String(endpoint)

The output is something like this - [B@38b1c3e8
3) endpoint = testRunner.testCase.getTestStepByName("GET").getHttpRequest().getEndpoint()

Output is something like this - https://customer-tst.api-pa.com

4) endpoint = context.testCase.getTestStepByName('GET').getPropertyValue("Endpoint")

Output is something like this - https://customer-tst.api-pa.com

So basically I am failed to get complete URL. Can someone please help me to get a solution for this.

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

Re: How to get Endpoint from the Request

@ranujn 

 

You gave me this response right?

 

{
"data" : {
"token" : "sidayf8r4jhrdsuf97adif09rujkfhw.8regiu6sy9s7d6fsa87s87439ykhkhfjdsbfsdf"
}
}

And I provided the code based on that. If you are getting the error. In that case, "data" attribute is not there in your response. You can pass the reponse to JsonSlurper. please ad few more lines of code:-

 

 

 

import groovy.json.JsonSlurper

def slurper = new groovy.json.JsonSlurper()
def response = context.expand('${API_Name#Response}') def slurp = slurper.parseText(response)
def token = slurp.data.token //Considering "data" and "token" as JSON attributes.

 

 

View solution in original post

17 REPLIES 17
Super Contributor

Re: How to get Endpoint from the Request

If you have REST endpoint, it consists of Resource path also with the endpoint. So Did you mean that you want thre resource path also added to endpoint?

 

If it is like that, then please try below code:-

 

String endPointUrl = testStep.getHttpRequest().getEndpoint();
String path = testStep.getHttpRequest().getPath()
String actualURL = endPointUrl+path

//Print actualURL
Contributor

Re: How to get Endpoint from the Request

Yeah, You got me correctly. 

 

I used the above script in the Groovy script to get Rest API endpoint plus resource path. but I am getting below error message. Am I doing something wrong here?

Tue Jan 22 16:39:16 AEDT 2019:ERROR:An error occurred in the script of the Groovy Script test step [Loop End]:
Tue Jan 22 16:39:16 AEDT 2019:ERROR:groovy.lang.MissingPropertyException: No such property: testStep for class: Script20
groovy.lang.MissingPropertyException: No such property: testStep for class: Script20
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script20.run(Script20.groovy:1)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:98)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:82)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:156)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:329)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

 

Super Contributor

Re: How to get Endpoint from the Request

//Considering that testStep is the object which means you need to pass your URL there.

def testStep = testRunner.testCase.getTestStepByName("YOUR REST REQUEST NAME")

else directly use this code:-

 

String endPointUrl = testRunner.testCase.getTestStepByName("YOUR REST REQUEST NAME").getHttpRequest().getEndpoint();
String path = testRunner.testCase.getTestStepByName("YOUR REST REQUEST NAME").getHttpRequest().getPath()
String actualURL = endPointUrl+path

Accept as solution, if this helps you out and don't forget to give Kudos. Smiley Happy

Contributor

Re: How to get Endpoint from the Request

Yes, it does work. However, it's showing a dynamic variable, not the value.

 

Like this https://customer-tst.api-pa.com/{path1}{token}

 

I need the value of path1 and token along with endpoint. 

 

FYI:- 

path1 getting populated from excel and token getting populated from previous API response.

Highlighted
Community Hero

Re: How to get Endpoint from the Request

@ranujn,
Where did you place the given script?
What the test steps (include its type) in the test case?
Do you need to access the endpoint before the REST request test step? or after the test step?
It would be good to understand better if the use case is provided which will reduce both your time and those who trying to help.



Regards,
Rao.
Community Hero

Re: How to get Endpoint from the Request

A screen shot or actual script you tried will also help!


Regards,
Rao.
Contributor

Re: How to get Endpoint from the Request

Please find the screenshot here. I need to access the endpoint after executing the request.

 

 

 

Community Hero

Re: How to get Endpoint from the Request

Just wondering how come url contains {token} etc?

 

See below in three stages where it does not show {} pattern in the url in test case or test step. Only exception is REST method definiton.

rest-template-sample.png

 

Would you please clarify?



Regards,
Rao.
Super Contributor

Re: How to get Endpoint from the Request

if path1 should be populated from excel. Then you should use DataSource testStep here:-

def path1 = ${DataSource#PATH1} //Considering PATH1 is column name in your excel.

And then append it with endpoint url. Also, for the token, just get the response of previous API and fetch the token from there:-

def response = context.expand('${previous API#Response}')
//Fetch the token out of the response using XmlHolder()

And append this also in the endpoint url.

 

New Here?
Join us and watch the welcome video:
Top Kudoed Authors