cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Opa5 FileUploader

wojciech712
Member
0 Kudos
367

Hello!

I struggle a bit with Opa5 testing and cannot find any information about it in the web.

This is my file Uploader.

<u:FileUploader 
class="sapUiTinyMarginBegin" 
id="fileUploader" 
width="100%" 
uploadComplete="onUploadComplete" 
httpRequestMethod="Post" 
placeholder="Pick a file" 
name="fileUploader" 
change="handleUpload"
fileType="csv" 
buttonText="Browse" /> 


<m:Button type="Accept" 
text="Upload" 
press="UploadPress"
ariaDescribedBy="acceptButtonDescription genericButtonDescription" />

I need to simulate uploading of a file and then to check if other logic is fired succesfully.
There is no problem with the second part but the first one is too hard:p All info that I found in web is here https://stackoverflow.com/questions/45605572/sapui5-opa5-how-to-upload-a-file-using-opa5-script and here https://answers.sap.com/questions/283913/sapui5-opa5-how-to-upload-a-file-using-opa5-script.html obviously is not sufficient. There is no guide in documentation also.

I tried something like this but test itself passes and nothing happens. No data are uploaded. Obviously this code is incorrect but since there are no errors i can't debug it:)

return this.waitFor({
id: "fileUploader", 
controlType: "sap.ui.unified.FileUploader", 
viewName: sViewName, 
success: function (oFileUploader) {


var data =<myData>
var blob = new Blob([data], { type: "text/plain" });
var file = new File([blob], "data.txt", { type: "text/plain" });
var fileInput = oFileUploader.getFocusDomRef(); 
fileInput.files = [file];
var event = new Event("change", { bubbles: true, cancelable: true, }); 
fileInput.dispatchEvent(event);

setTimeout(function () 
{ Opa5.assert.ok(true, "File upload triggered successfully"); }, 1000); }, errorMessage: "File uploader not found or not interactive", timeout: 5000, }); },

Would appreciate any help!

Accepted Solutions (0)

Answers (1)

Answers (1)

ivan1547
Associate
Associate
0 Kudos

Hi,

You can use the following method: fireChange.

In your case, it would look like:

 

 

return this.waitFor({
    id: "fileUploader", 
    controlType: "sap.ui.unified.FileUploader", 
    viewName: sViewName, 
    action: function (oFileUploader) {
        var data = <myData>;
        var blob = new Blob([data], { type: "text/plain" });
        var file = new Blob([blob], "data.txt", { type: "text/plain" });
        fileUploader.fireChange({ newValue: "data.txt", files: [file] });
    }
});