Forum Discussion

mpourali's avatar
mpourali
Occasional Contributor
9 years ago

SmartBear/SoapUI5.2.1 opensource: problem with "... No signature of method: java.io.File.exist()

Thanks, in advance.

Story: I am trying to See if a file exists on the Network drive, then Delete it.

A- I have commented out most lines to narrow down the issue.

B- I could not find a working example code in Groovy either.

 

1. In SoapUI 5.2.1, set the Script Language t- JavaScript.

2. Execute the attached script.

 

It results in:  "groovy.lang.MissingMethodException: No signature of method: java.io.File.exist() is applicable for argument types: () values: [] Possible solutions: exists(), list(), list(java.io.FilenameFilter), wait(), wait(long), print(java.lang.Object) error at line: 9 "

 

=========

def xmlfilepath = new File ('\\\\sharedNET\\Mirth\\QA\\External\\HTTPS\\myfile.xml') ;
def IDXfilepath = new File ('\\\\Shareddevice\\c$\\SFTP\\Dest\\QA\\Results\\myfile.idx') ;

//var xmlfilepath = '\\\\sharedNet\\Mirth\\QA\\External\\HTTPS\\myfile.xml' ;
//var IDXfilepath = '\\\\SharedDevice\\c$\\SFTP\\Dest\\QA\\Results\\myfile.idx' ;
log.info(xmlfilepath);
log.info(IDXfilepath);

if (xmlfilepath.exist() ){
  // file exist
log.info("XML file exist");
delete (xmlfilepath);
//xmlfilepath.delete(xmlfilepath);
}

if (!xmlfilepath.exists() ) {
  // file is not exist
    Log.info("XML file does not exist");
}

//if ( IDXfilepath.exists() ){
  // file exist
//    Log.info('IDX file exist');
//    IDXfilepath.delete();
//}
//if (!IDXfilepath.exists()) {
  // file is not exist
//    log.info("IDX file does not exist");
//}

 

============

  • The groovy script for your goal is following:

     

    def f = new File('//server/path/test.txt')
    
    if (f.exists()) {
    	f.delete()
    }

    You can use Javascript as well. SoapUI is a bit tricky with changing the scripting language. When I change from Groovy to Javascript (on project level), I can use Javascript. When I switch back to Groovy, the script is still executed as Javascript. 

     

    I had to close the test case editor and reload the project. Then the script is executed by the language which is set on the project. 

     

  • KarelHusa's avatar
    KarelHusa
    Champion Level 2

    The groovy script for your goal is following:

     

    def f = new File('//server/path/test.txt')
    
    if (f.exists()) {
    	f.delete()
    }

    You can use Javascript as well. SoapUI is a bit tricky with changing the scripting language. When I change from Groovy to Javascript (on project level), I can use Javascript. When I switch back to Groovy, the script is still executed as Javascript. 

     

    I had to close the test case editor and reload the project. Then the script is executed by the language which is set on the project. 

     

    • mpourali's avatar
      mpourali
      Occasional Contributor

      Thanks KarelHusa. The code snippet you've provided works for me great.

       

      For some strange reason, after setting the language to JavaScript  and even after existing SoapUI then reloading it. I could not run the JavaScript.  the funny thing is the same code run OK a few days ago.!!!

      Thanks again, mpourali

  • nmrao's avatar
    nmrao
    Champion Level 3
    Default script type is groovy. Any specific reason to choose Javascript over Groovy?

    Is the script that you attached is Javascript?
    • mpourali's avatar
      mpourali
      Occasional Contributor

      Thank nmrao,

      The only reason I have is that I do not know anybody with Groovy background in house and some of the examples on the internet were not working for me. I used JavaScript just in case if the test fails, I could show the 'automation' code to the dev team.

       

      Funny thing is that this code worked at some point, then stopped working. may be it got confused switch back and forth between JavaScript and Groovy too many times. I even closed the whole SoapUI and reopen after every language switch!!!

       

      Thanks again, mpourali