Forum Discussion

vpachpute1's avatar
vpachpute1
Frequent Contributor
8 years ago
Solved

Groovy : How to give absolute file path of file.

Hi

 

I want to give absolute file path in Groovy. I have following code.

 

// Option 1 : this works on my local. but not on Jenkins/maven which is on server. As there is relative path of my local

 

request = xmlParser.parse("/home/vishalpachpute/API/Responses/Response_SelfFullTrans.xml")

 

// Option 2 : This works only in Maven/jenkins. Not in Ready API tool. In Ready API tool, It shows java.io.FileNotFoundException: /opt/SmartBear/ReadyAPI-1.9.0/bin/Responses/Response_SelfFullTrans.xml


request = xmlParser.parse("Responses/Response_SelfFullTrans.xml")

 

So can you please suggest any such absolute path so that it will work on both SOAP UI tool and Maven.

 

Kindly help me on this. Thanks in advance.

 

Regards

Vishal

 

  • Since the path changes machine to machine, you need to use a variable / project level property, say BASE_DIRECTORY, set this value according to machine, here "/home/vishalpachupute" and rest of the path maintain the directory structure for the resources being used.

    In the script:

    def prefix = context.expand('${#Project#BASE_DIRECTORY}')
    def request = new File("${prefix}/API/Responses/Response_SelfFullTrans.xml").text

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3
    Since the path changes machine to machine, you need to use a variable / project level property, say BASE_DIRECTORY, set this value according to machine, here "/home/vishalpachupute" and rest of the path maintain the directory structure for the resources being used.

    In the script:

    def prefix = context.expand('${#Project#BASE_DIRECTORY}')
    def request = new File("${prefix}/API/Responses/Response_SelfFullTrans.xml").text