18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Sahi and RichFaces FileUpload
Hello,
We have several web applications which are using the RichFaces FileUpload component (see http://livedemo.exadel.com/richfaces-demo/richfaces/fileUpload.jsf).
I cannot use the sahi _setFile for this component. Is there a way in sahi to upload a file with this component?
Thank you in advance.
Best regards,
Werner
We have several web applications which are using the RichFaces FileUpload component (see http://livedemo.exadel.com/richfaces-demo/richfaces/fileUpload.jsf).
I cannot use the sahi _setFile for this component. Is there a way in sahi to upload a file with this component?
Thank you in advance.
Best regards,
Werner
Comments
In the meantime, I've already found a way to upload one file with the RichFaces FileUpload component.
However, there remains one problem and I don't know how to solve this:
There are validations performed on the file by the component (for example, it checks that the file has the correct extention). If this check fails, the component shows an error message and doesn't send the file to the server.
But during the next test iteration, sahi still seems to remember the 'wrong' file and will upload this one to the server in stead of the new one.
Is there a way to cleanup the files that were not send correctly with the _setFile function?
That was a great work around you have figured out. Sorry we could not help out on that.
To cleanup the file set via _setFile, use this:
Explanation:
_setFile() registers the form action URL with Sahi, so that the file is added to the request. This registration is removed once the file is successfully added. Since it never got invoked due to js validations, we need to explicitly unregister it. In the snippet above, much of the code is to get the form action URL. Once it is retrieved, the URL is de-registered using _removeMock
Regards,
Narayan
When I paste the code in my testscripts, I get the following error:
I also see a warning at the start of the test script in the log file:
Regards,
Narayan
Thanks for your help. However the piece of code didn't do the job. I'll describe the situation and what's going wrong:
-Test1: Upload a correct file with extention .xml => OK, file is uploaded
-Test2: Upload a wrong file with extention .txt => OK, file is not uploaded, because the button to upload the file is not visible and an error message appears
-Test3: Upload again a correct file with extention .xml => NOK, the .txt file from test2 is still send to the server even when the function unsetFile is executed after the setFile in test2 or before the setFile in test3.
However, I found a proper workaround (with the help of your first explanation):
Since the event to show the button to upload the files or the error message is triggered by changing our own added hidden field, I wait to perform the _setFile method until I'm sure the file needs to be uploaded (meaning no error message is shown).