"File path not found" error while running on Jenkins

58 views
Skip to first unread message

Ramapriya Prasathe

unread,
Apr 22, 2025, 2:40:05 AMApr 22
to Selenium Users

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:
  1. 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!

Adrian

unread,
Apr 22, 2025, 5:35:55 PMApr 22
to Selenium Users
Hi,
Start with the obvious.  Does the file actually exist at /home/jenkins/agent/workspace/remitbee-selenium-v3/src/test/resources/fileData/sampleFile.pdf
Then does the Jenkins user have access to the location where the file exists?


Cheers,
Adrian.
Reply all
Reply to author
Forward
0 new messages