Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, windows and java based applications. Get your 30 day free trial.

Discuss your Sahi Pro usage patterns, best practices, problems and solutions. Help others solve their problems and seek help from the community when needed. If you need specific support on your application, please email support @ sahipro.com

Uploading files in Angular environment

SadanaSadana Members
edited September 2013 in Sahi - Open Source
Hi again people!

I have been trying to get file uploading to work in my system. Extra challenge is created by Angular and Java-language.
This is how uploading manually works:
1. Click the Upload-link.
2. Upload-dialog opens and there I have to click browse-link.
3. Windows File upload controlling window opens and there I choose the file I want to upload.
4. After clicking Open-button in that window it will be closed and also upload-dialog is closed automatically and file is uploaded to the system.

Here's the element list of upload-feature.
<div id="upload-dialog" class="reveal-modal open">
<form class="ng-pristine ng-valid" enctype="multipart/form-data" encoding="multipart/form-data">
<div class="row">
<div class="large-12 columns">
<uploader action="/attachment/upload" class="ng-isolate-scope ng-scope">
<input type="file" name="uploader_file" onchange="angular.element(this).scope().sendFile(this);">

So far I have been executing the following lines:
browser.submit("Upload").click();  //Opens upload-dialog
browser.file("uploader_file".click(); //Opens Windows File upload controlling window
browser.execute("_sahi._file('uploader_file').type = 'text'");
browser.textbox("uploader_file").setValue(fileName);

Second line is preventing any action until it's closed manually. So I have been trying to get system work without it.
I think the problem is that how to submit the file. So far I have been able to write name of the file to the textbox, but nothing else seems to happen. At least I don't see any error in any log.

Answers

  • SadanaSadana Members
    Developers has been doing some changes to their code and I have been trying to get this to work again.

    Here's the code I have been trying to use.
    browser.submit("Upload").click();
    browser.file("uploader_file").setFile(FileName);
    browser.execute("_sahi._file('uploader_file').type = 'text'");
    browser.textbox("uploader_file").setValue(FileName);
    

    Finally application is able to recognise that there is some file to upload and it will close the pop-up window by itself.
    But it seems some wrong string is going to server. As a response I'm getting error:

    HTTP Status 500 - java.lang.NumberFormatException: null
    The server encountered an internal error that prevented it from fulfilling this request.

    If I'm doing the case manually, then there will be no errors at all.

    Any idea what could be wrong?
  • SadanaSadana Members
    edited April 2014
    I have been checking what kind of information there is in the network logs.

    When I'm uploading file manually then in Chrome there is the following information in the Request Payload:
    WebKitFormBoundaryhgjfoisajres
    Content-Disposition: form-data; name="uploader_file"; filename="Textfile.txt"
    Content-Type: text/plain
    

    But when I'm trying to upload file by Sahi then I'm getting the following information:
    WebKitFormBoundaryjgrsoiatjsao
    Content-Disposition: form-data; name="uploader_file"
    
    "Textfile.txt"
    

    Information of the file type and also attribute filename is missing. Is that something what Sahi should be handling or what?
Sign In or Register to comment.