Ask a Question

Connect to Network Path with Windows security using Groovy Scripting

Occasional Contributor

Connect to Network Path with Windows security using Groovy Scripting

Hi , 

I have the below  API Response which contains a Key : Attachment Path.

I am trying to verify using Groovy Script Test Step if the file exists on that Path or not. The thing is when i try to open the path manually , i get a Windows Security popup (asking me to enter username and password) and only then can i enter the path and verify the image exists or not on that location.


I found a workaround where Iff i Map this Attachment Location path in widows (maps as Z drive),  i am able to use groovy to check for the existence of the image. But the problem with that is , each time my PC restarts , the Mapped drive is gone and i have to remap it for this test step to run.


Can some one help me if there is a way to validate the existence of the image on this server


"Bulletin" : {
"BulletinID" : "******-***-4e62-a84e-85cce1b49540",
"UniqueKey" : "TS88-****",
"CreatedByID" : "8989",
"Title" : "Bulletin_edit",
"ModuleLookupID" : "35453452",
"DateClosed" : null,
"IsActive" : true,
"DateCreated" : "2019-06-17T03:10:50.857",
"ModifiedByID" : "4354333345",
"DateLastModified" : "2019-06-19T06:55:38.08",
"LastModifiedBy" : "abc",
"COMSmodules" : "sdadasdadas"
"Section" : "Bulletin",
"FileTitle" : "title",
"FileName" : "filename.jpg",
"AttachmentPath" : "\\\\\\abc00$\\QA\\Attachments\\Bulletins\\filename.jpg",
"AttachmentID" : "54546"



Groovy Script : 

import groovy.json.JsonSlurper
def response = context.expand( '${GET Request#Response}' )
def jsonSlurper = new JsonSlurper()
def jsonObject = jsonSlurper.parseText(response)

def path = jsonObject.AttachmentPath.toString() //Get the attachment Path from the API Response path
path = path.replaceAll("]","")

Split = path.split(/[\\]/)

size = Split.length
FileName = Split[size-1] "File name is : " +FileName


Filename = "Z:\\\\"+FileName \\Mapped drive file name "Mapped Path : " +Filename

File file = new File(Filename) "Check if the File exists on the Mapped Path : " +file.exists()

assert file.exists().toString()=="true","File does not exist on the Server: Z:\"

Community Hero

Hi @ashutosh 


i can't help with the ReadyAPI!/SoapUI/Groovy option - but i was wondering about whether you'd accept a workaround?


Your User Account Control is enabled and this is what's hindering the file Open windows dialogue being generated.  Could you not disable the UAC?  (depends if you have local admin rights or if Policy is forcing it enabled)


If you can't disable the UAC and the issue is that you lose the drive mapping after restarting your machine - could you not create a login script to automatically map the drive on startup? i.e. create a .bat file (using net use command to map the drive) and stick the .bat file in one of the many startup folders/registry settings.


it's real simple - the following link tells you how to do it - link


Just an option....





if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
SmartBear Alumni (Retired)

Hi all,

@richie thanks for looking into this!


@ashutosh does the workaround work for you?


Olga Terentieva
SmartBear Assistant Community Manager

SmartBear Alumni (Retired)

Let me mark Richie's workaround as a solution for now.

@ashutosh, you can always get back to this thread if you would like to investigate this further.

Have a great day!



Olga Terentieva
SmartBear Assistant Community Manager

Showing results for 
Search instead for 
Did you mean: