Forum Discussion

ashutosh's avatar
ashutosh
Occasional Contributor
5 years ago
Solved

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" : "\\\\blahblah.com\\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
log.info path
path = path.replaceAll("]","")

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

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

 

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


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

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

  • 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....

     

    ta,

     

    richie

3 Replies

  • richie's avatar
    richie
    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....

     

    ta,

     

    richie

    • Olga_T's avatar
      Olga_T
      SmartBear Alumni (Retired)

      Hi all,

      richie thanks for looking into this!

       

      ashutosh does the workaround work for you?

       

      • Olga_T's avatar
        Olga_T
        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!