Search code examples
javaautomationcucumberrest-assured

how to specify a path for a file in repository ( java ) , so that my automation test won't fail


I'm testing an API with rest assured, programming language is JAVA, I'm having little issue, the issue is , I have to send an image using rest assured, and it's being sent successfully locally, but when i push it to git , having problem with specifying the path, and all my tests are run on TeamCity , and I get my cucumber report, report as follows

java.io.FileNotFoundException: C:\Users\nameOfUser\Downloads\38250987.jpeg (The system cannot find the path specified)

I hope I have delivered the issue descriptive enough, in case if u have any questions,doubts please do ask your questions, hoping for your help and cooperation, thanks in advance!

the code as follows

public static Response SendAnImage(String prodID,Cookies cookies)  {

     File file = new File("C:\\Users\\userName\\Downloads\\38250987.jpeg");
        System.out.println("is file found ---->  "+file.exists());

        Response response = given()
                .multiPart("file", file, "image/jpeg")
                .when()
                .cookies(cookies)
                .post("/api/product/"+prodID+"/file/false");


        return response;


    }

Solution

  • You can put your file in src/test/resources folder, then create a new File like this:

     File file = new File("src/test/resources/38250987.jpeg");