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

  • String file = vars.get("downloadedFileName");"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);"file address is " + filePath);
    File file1 = new File(filePath);
        //exists = file.exists();"File existance result"+file1.exists());
        if (file1.exists())  
"file exists, and it is a file");
        }else{"file does not exists");
    file1.createNewFile()"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