Ask a Question

Save endpoint and resurce path in to a a notepad in readyApi

ABCDEFG
Contributor

Save endpoint and resurce path in to a a notepad in readyApi

Greetings,

I need to save endpoint and resurcepath in to a notepad in readyApi? I tried using below script to generate the endpoint; however i don't know how to get the resource path and combine it as 1 string. Could please help 

def endpoint = context.expand( '${TestCaseName#Endpoint}' )
log.info endpoint

Thanks!
4 REPLIES 4
HimanshuTayal
Community Hero

Re: Save endpoint and resurce path in to a a notepad in readyApi

hi @ABCDEFG

 

You can use below code for finding Endpoint and Resource Path

 

 

def endpoint = context.testCase.getTestStepByName("Request").getPropertyValue("Endpoint")
def resourcePath =  context.testCase.getTestStepByName("Request").resource
def data = endpoint + "/" + resourcePath def file = new File("D:/test.txt").write(data.toString(),"UTF-8")

 

Do Like if you Find the Solution

 

Thanks,

Himanshu Tayal


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
ABCDEFG
Contributor

Re: Save endpoint and resurce path in to a a notepad in readyApi

Thank you @HimanshuTayal for the response. 

 

I tried this in my test case (having only 1 test step) and getting this error message. Could you check this out?

java.lang.NullPointerException: Cannot invoke method getPropertyValue() on null object error at line: 1

 

 

Once above issue is resolved, i have another question: Suppose if i want to use this in multiple test steps included test case; how would this script identify the test step  which i need to this script to identify?

 

Thanks in advance

 

Thanks,

ABCDEFG

HimanshuTayal
Community Hero

Re: Save endpoint and resurce path in to a a notepad in readyApi

Hi @ABCDEFG

 

The code i have given to you, please replace 

 

def endpoint = context.testCase.getTestStepByName("Request").getPropertyValue("Endpoint")
def resourcePath =  context.testCase.getTestStepByName("Request").resource
def data = endpoint + "/" + resourcePath def file = new File("D:/test.txt").write(data.toString(),"UTF-8")

The part i have BOLD, from the name of your request

 

And the answer to your second question is, just replace the Request with the Steps name you are having or you can apply loops as well on the Test Case.

 

Do Like and Accept if you Find the Solution

 

Thanks,

Himanshu Tayal


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
ABCDEFG
Contributor

Re: Save endpoint and resurce path in to a a notepad in readyApi

Great @HimanshuTayal. its working. 

 

however when retrieving the 'resourcePath' path; its having a veribiage "RestResource:" right infront of the resource path, Do you know how to get the resourcepath with out this verbiage? 

 

sample response ==  'RestResource: /cloud-services/api/test/v1/health'

 

Else i have to write another block of code to trim it. 

 

Thanks!

 

cancel
Showing results for 
Search instead for 
Did you mean: