How to get Endpoint from the Request
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
//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. 🙂
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Would you please clarify?
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
