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.
_setFile doesn't work for me
Hi Experts,
I have a form which uploads an XML file.
The scenario is to select an xml file and then press the Import button.
I'm using Sahi V2 Release 2009-05-21 and Firefox 2.0.0.20 browser on Windows XP SP3.
I tried :
a)
b)
c)
d) Tried Modifying the xml using javascript
e) Setting the mime type for xml [ as suggested in sahi.co.in/forums/viewtopic.php?id=48 ]
f) Modifying the document and setting the value of the field.
None of the above worked.
How can I get this working ?
Is there a way to enable logging in the Sahi Proxy that could help debug the issue ?
Any pointer is welcome and appreciated.
thanks,
Hari
I have a form which uploads an XML file.
The scenario is to select an xml file and then press the Import button.
I'm using Sahi V2 Release 2009-05-21 and Firefox 2.0.0.20 browser on Windows XP SP3.
I tried :
a)
_setFile(_file("importFile"), "C:\\test.xml");
_click(_button("Import"));
b)
_call(_file("importFile").type = "text");
_setValue(_textbox("importFile"), "C:\\test.xml");
_click(_button("Import"));
c)
_call(_file("importFile").type = "text");
_setValue(_textbox("importFile"), "C:\\test.xml");
_call(_textbox("importFile").type = "file");
_click(_button("Import"));
d) Tried Modifying the xml using javascript
<browser>
function setImpFile()
{
var x = document.getElementsByTagName('input');
for (var i=0;i<x.length;i++) {
if (x[i].type != 'file') continue;
var newAtt = document.createAttribute("value");
newAtt.nodeValue = "C:\\test.xml";
x[i].setAttributeNode(newAtt);
}
}
</browser>
_call(setImpFile());
_click(_button("Import"));
e) Setting the mime type for xml [ as suggested in sahi.co.in/forums/viewtopic.php?id=48 ]
f) Modifying the document and setting the value of the field.
var x = document.getElementsByTagName('input');
for (var i=0;i<x.length;i++) {
if (x[i].type != 'file') continue;
x[i].value="C:\\test.xml";
}
I get a "NS_ERROR_DOM_SECURITY_ERR: Security error" error
None of the above worked.
How can I get this working ?
Is there a way to enable logging in the Sahi Proxy that could help debug the issue ?
Any pointer is welcome and appreciated.
thanks,
Hari
Tagged:
Comments
? Do you get any javascript errors or validation errors?
Does your application use a single URL for all requests or is the form submitted to a unique URL (different from URLs of other pages) ?
I also did not get any javascript / validation errors.
The console has the following text added after running this test case :
The form is submitted to the same URL. It does not change per request etc.
My app complains with an error message / stack trace about "Content-Length: 0" which looks like the file does not seem to be uploaded.
The same works when I do the upload manually.
NOTE :
There is no space between h and ttp in the sahi console.
The forum does not allow me to post URLs since I'm a new member.
In this case my app throws an exception ( same as before )
With C:/testAXX.xml ( a non-existent file ), I see the following error in the Sahi console :
And the browser shows an empty page ( Looks like the request did not go thru to my app )
Thank you for your help!
A snippet for the request when using Sahi :
1428251156286
Content-Disposition: form-data; name="importFile"; filename=""
Content-Type: application/octet-stream
and there is no file content here.
When doing the same file upload manually I see :
29756655028618
Content-Disposition: form-data; name="importFile"; filename="test.xml"
Content-Type: text/xml
<content of test.xml here>
So it looks like the mime type seems to be a problem.
I had added the following line to sahi's mime-types.mapping
.xml text/xml
and restarted the sahi proxy server.
I havent actually checked the mime type recieved by the server.
I'm using Tomcat 5.5. I'll have to figure out how to get Tomcat to check this since I did not write the application.
Any quick ideas.
I'm thinking of using the SOAP TCP Tunnel/Munitor in the following way.
Sahi / Firefox ==> Proxy === > Tomcat
With SAHI :
Without SAHI :
As you can see SAHI seems to be adding a Content-Length header to all the form data, which is not present when directly using a browser.
My App also complains about a Content-Length:0
Is it possible to suppress the Content-Length header ?
If not by default if some configuration option can be provided to suppress the Content-Header it would be great!
Does my analysis make sense ?
What you say could very well be the reason. I just tested it with some other test pages and it seems to be working there. So it is specific to your application. How urgent is the need? I can send you a build with that content length configurable and we can check if it works. It will take some time though.
Regards,
Narayan
I certainly don't need it before Monday.
I will also look at the code and try figuring out a crude hack that works for me.
Thank you for your support!
I received the build.
I will test as soon as I can and let you know how it went..
Thanks Again!
The fix doesn't remove the Content-Length header for all the multipart entries.
Here is the log from the Sahi proxy window when I attempted the same test as before with the new sahi.jar and sahi.properties updated :
Please see that the Content-Length for the test.xml :
Here's the complete output from the Sahi proxy :
Now it works perfectly!
Thanks Narayan for the quick response to my all updates on this issue!
I did not notice this before, but you are doing a _setValue(_file("ODTPath"), "smoke.odt");
It should be _setFile(_file("ODTPath"), "smoke.odt");
(It may still fail if you have javascript validations to check if a file has been set. Ping me if that is the case)
Regards,
Narayan