Forum Discussion

ABCDEFG's avatar
ABCDEFG
Contributor
6 years ago

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

  • 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

    • ABCDEFG's avatar
      ABCDEFG
      Contributor

      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's avatar
        HimanshuTayal
        Community Hero

        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