Forum Discussion

saurabhsharma09's avatar
saurabhsharma09
Contributor
11 years ago

[R]How to read files in directory present under project root

Hello,

I have multiple files inside a folder "attachments" which is present under project directory.
I have to read each file one by one, attach it to the REST service and send as attachment.
I've selected "Resource root" as ${projectDir} and trying to create url to read files in a Groovy test Step.
Through groovy in eclipse i am able to read files successfully however in soap ui i am not able to do so as Soap UI is searching the folder inside it's Installation directory instead of project directory
Below is groovy code snippet which i am using in eclipse:-
def url="E:\\Document_Service\\attachments"
new File(url).eachFile{file ->
if(file.exists()){
println(file.name)
}
}
I've tried to create url and substitute it in the code above but i think i am doing something wrong.
def projectroot = context.expand('${projectDir}')
def url ="${projectroot}\\attachments"
I've added screenshot for my directory structure also.
Could you please point me to the correct direction?


Thanks,
Saurabh

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    Try "${projectroot}/attachments", instead of \\. Let me know if this doesn't help so that I can look further into it.

    Regards,
    Temil
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    So if you get the project path using,
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def projectroot = groovyUtils.projectPath

    So you can construct URL using,
    def url = projectroot +"\\attachments"

    This should work.

    Thanks,
    Jeshtha
  • Hello,

    I am able to read files successfully now,attach it to REST request and send it successfully.

    Thanks,
    Saurabh