18 January 2026:


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.

Any improvements with file upload ?

lalwaniajaylalwaniajay Members
edited November -1 in Sahi - Open Source
I have gone through the sahi documentation which mentions the limitations of sahi in uploading a document when the control has javascript validations.
I wanted to know if there is any possible workaround ?

I was using selenium the other day and i realized that selenium could populate the text box of the upload control. I mean <input type=file> type control.

Though sahi can help upload a document if the control is not validated, it is not the case in most of the websites as validations are put on each control.

I also do not want to use selenium to automate document uploads. Its a clear overkill.

A workaround would be great.

Thanks,
Ajay

Comments

  • narayannarayan Administrators
    Hi Ajay,

    As of now, we only suggest workarounds to get around the file upload verification problem. One easy work around is to change the type of the field to text, and set its value correctly.

    Eg.

    Suppose you needed to do
            _setFile(_file("file"), "scripts/demo/uploadme.txt");
    

    You would now do
        _setFile(_file("file"), "scripts/demo/uploadme.txt");
        _call(_file("file").type = "text"); // Change the type to text
        _setValue(_textbox("file"), "scripts/demo/uploadme.txt"); 
             // Set the value for validation. note how _file("file") becomes _textbox("file")
    

    This works only if the application is not checking for the "type" attribute.

    Most other solutions need extra privileges on the browser or using tools which may not work properly in multithreaded mode because of focus problems.

    Caution: When you do something like this, you are facilitating automation of other parts of the system but not really verifying the fileupload functionality. Make sure you test file upload manually before you release the software.

    Regards,
    Narayan
  • Hi Narayan,
    Thanks for the workaround.
    I tried using it. Works well but yet the file is not uploaded.
    My current page calls a servlet which accepts stream data so my file is yet not uploaded even though this code bypasses the javascript validations.
    I hope you guys will come up with something soon.
    Till then i will just try to integrate sahi and selenium(only for uploads)

    Regards,
    Ajay
  • narayannarayan Administrators
    Hi Ajay,

    I think the file is uploaded but the mime-type of the file may be wrong.
    Check what the file type is, and look at whether there is an entry for the type of file you are uploading in sahi/config/mime-types.mapping
    If it is not in that list, add the fie extension and the correct mime type, restart Sahi and try again.

    Some one in the development team may be able to help you with the mime-type. Or you could post the file extension here.

    Regards,
    Narayan
  • Hi Narayan,
    The extension of the file is .xpdl (It is an xml format file)
    so the mime type file includes:
    .xpdl text/xml
    .xml text/xml

    yet it doesn't work !
  • OldikOldik Members
    I have also maybe same problem with uplouding .xml file. Is there already any solution?
  • Hi Oldik,

    Please create a new forum post.

    Could you please let me know where exactly you are facing problem.

    Here is the Documentation for file upload:

    http://sahi.co.in/w/_setfile/

    Regards
    Sumitra
Sign In or Register to comment.