file.exists() is returning false in JSR223 Assertion.When hit file path in windows explorer



  • String file = vars.get("downloadedFileName");
    log.info("file name is " + file);
    String path= "C:\\Users\\abhishek\\Desktop\\JMeter\\apache-jmeter-3.3\\bin\\";
    String filePath = path+file+".pdf";
    //System.out.println("file address is " + file);
    log.info("file address is " + filePath);
    
    File file1 = new File(filePath);
        //exists = file.exists();
        log.info("File existance result"+file1.exists());
        if (file1.exists())  
        {
          log.info("file exists, and it is a file");
        }else{
    log.info("file does not exists");
    file1.createNewFile()
    log.info("file does not exists and created new is "+file1.createNewFile());
    }
    

    Can anyone explain to me what the problem in my code is? enter image description here



  • Looking into JMeter Test Elements Execution Order it looks like:

    0 Configuration elements

    1 Pre-Processors

    2 Timers

    3 Sampler

    4 Post-Processors (unless SampleResult is null)

    5 Assertions (unless SampleResult is null)

    6 Listeners (unless SampleResult is null)

    So if you save the file using i.e. Save responses to a file which is a Listener your JSR223 Assertion is executed before the file appears.

    If this is the case - just change JSR223 Assertion to JSR223 Listener and make sure it's located below the Save Responses to a file listener.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2