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.

Not able to upload file, even after passing third argument

nagarnagar Members
edited April 2012 in Sahi - Open Source
Hi All,

I need to upload a binary file on my application. I am using this code (let say, binary file name is: "abc"):
_setFile(_file("filename"), "abc","corporate/webpages/index.jsp");

if(_isIE()){
_call(_file("filename").outerHTML = _file("filename").outerHTML.replace(/type=file/, "type=text"));
_call(_textbox("filename").value= "abc");
}
else{
_call(_file("filename").type = "text");
}

_setValue(_textbox("filename"), "abc");
_click(_button("Upload"));

URL (third argument) remains same, while either uploading using Sahi or uploading manually..
URL is: http://10.20.20.227:1180/corporate/webpages/index.jsp

I also tried with whole URL as third argument, but still could not succeed. As the resultant it shows Error 404: Page not found.
No error message found on Sahi console.

Please help in this.
Thanks in Advance!

Comments

  • nagarnagar Members
    edited April 2012
    I also checked request response using firebug.
    It shows POST request on http://10.20.20.227:1180/corporate/Controller

    I also tried, third argument as:
    _setFile(_file("filename"), "abc","/corporate/Controller");

    AND

    _setFile(_file("filename"), "abc","http://10.20.20.227:1180/corporate/Controller";);

    but this time, "SAHI_ERROR" is displayed on the webpage.


    Any help will be highly appreciated.
  • nagarnagar Members
    Getting this on Sahi console:
    url: http://10.20.20.227:1180/corporate/Controller
    command: FileUpload_appendFiles
    Apr 28, 2012 4:56:10 PM net.sf.sahi.command.FileUpload appendFiles
    INFO: Uploading: fileName = CR500i_XN01.10_02_0_356 resolved to C:\sahi\userdata
    \CR500i_XN01.10_02_0_356
    Apr 28, 2012 4:56:11 PM net.sf.sahi.command.CommandExecuter execute
    WARNING: commandClass = >net.sf.sahi.command.FileUpload< commandMethod = >append
    Files<
    Apr 28, 2012 4:56:11 PM net.sf.sahi.command.CommandExecuter execute
    WARNING: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.sf.sahi.command.CommandExecuter.execute(CommandExecuter.java:55)
    at net.sf.sahi.command.MockResponder.getResponse(MockResponder.java:64)
    at net.sf.sahi.ProxyProcessor.handleDifferently(ProxyProcessor.java:164)

    at net.sf.sahi.ProxyProcessor.processAsProxy(ProxyProcessor.java:144)
    at net.sf.sahi.ProxyProcessor.run(ProxyProcessor.java:93)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Unknown Source)
    at java.io.ByteArrayOutputStream.write(Unknown Source)
    at java.io.OutputStream.write(Unknown Source)
    at net.sf.sahi.request.MultiPartRequest.getRebuiltRequest(MultiPartReque
    st.java:119)
    at net.sf.sahi.command.FileUpload.appendFiles(FileUpload.java:91)
    ... 10 more
  • nagarnagar Members
    edited April 2012
    Narayan,

    I am expecting some expert tips from you.

    Kindly look into this.
  • gaveyomgaveyom Members
    edited April 2012
    Nagar,

    hope this will help u, it's working fine for me, pls try this


    **********************************************************************


    _setFile(_file("SourceFileUpload"), "D:/fileName.txt");
    // Change the "type" attribute of file field
    if (_isIE()){
    _call(_file("SourceFileUpload").outerHTML = _file("SourceFileUpload").outerHTML.replace(/type=file/, "type=text"));
    }else{
    _call(_file("SourceFileUpload").type = "text");
    }
    // Set the value into the textbox
    _setValue(_textbox("SourceFileUpload"), "D:/fileName.txt");


    **********************************************************************

    Regards,
    G@veyom
  • nagarnagar Members
    Hi gaveyom,

    Thanks for the response...

    Browsing the file is not an issue for me. I am able to browse it successfully, using Sahi's workaround. The problem is, after clicking on "Upload" button, it is not being uploaded. Probably, due to third argument within _setFile API.

    Regards,
    nagar
  • Hi Nagar,

    Is it possible for you to share the file browsing work around.

    I have tried the following:

    _setFile(_file("SourceFileUpload"), filepath);
    // Change the "type" attribute of file field
    if (_isIE()){
    _call(_file("txtDocument").outerHTML = _file("txtDocument").outerHTML.replace(/type=file/, "type=text"));
    }else{
    _call(_file("v").type = "text");
    }
    // Set the value into the textbox
    _setValue(_textbox("txtDocument"), "filepatht");

    After changing the file into text, the value gets sets however when I click the "OK" button to commit changes, the converted input type changes back to input type = file and the field value becomes blank.

    If there is a way to browse using sahi controller, please share.

    thanks
  • nagarnagar Members
    Hi Emihle2010,

    It should not be the case, until & unless you change it's type, back to "file". May be you are changing it's type before clicking on "OK".

    Does your GUI page show any error when you click "OK"?

    thanks.
Sign In or Register to comment.