Hi Everyone,
I'm reaching out to get help with a "File not found" error that I'm encountering. The issue arises during file upload when running tests through Jenkins, although everything works perfectly fine when running locally.
Error Message (on Jenkins):"invalid argument: File not found : /home/jenkins/agent/workspace/remitbee-selenium-v3/src/test/resources/fileData/sampleFile.pdf"
What I've Tried So Far:
-
Updated the File Upload Method:
public void clickUploadPhotoBtn(String fileName) {
String projectRoot = System.getProperty("user.dir");
System.out.println("Project Root Directory: " + projectRoot);
String relativePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "fileData" + File.separator + fileName;
String absolutePath = projectRoot + File.separator + relativePath;
File file = new File(absolutePath);
if (!file.exists()) {
throw new RuntimeException("File not found at path: " + absolutePath);
}
uploadPhotoBtn.sendKeys(file.getAbsolutePath());
// String relativePath = "src/test/resources/fileData/" + fileName;
// File file = new File(relativePath);
// String absolutePath = file.getAbsolutePath();
// uploadPhotoBtn.sendKeys(absolutePath);
}
(The previously used version is now commented out.)
2. Added the file path on Jenkins file on our project
stage ("Test application") {
steps {
script {
// Inject the test file here
sh '''
mkdir -p src/test/resources/fileData
echo "Sample file path" > /home/jenkins/agent/workspace/remitbee-selenium-v3/src/test/resources/fileData/sampleFile.pdf
'''
withMaven {
sh """
mvn test -Dgroups=${params.groups} -Dbrowser=${params.browsers}
"""
}
}
}
}
Despite this setup, Jenkins still throws the "file not found" error. I’d appreciate any suggestions or insights if anyone has faced a similar issue or knows what might be going wrong.
Thanks in advance!