SamSaini
SamSaini

Reputation: 11

Facing issue while uploading document through protractor

I'm trying to upload document through protractor into my angular application, but I'm getting error after clicking on Upload button. I'm trying through following code: const absPath = path.resolve(_dirname, PathofFile); return $('input[type="file"]').sendkeys(absPath);

Protractor version: 5.4.2 Npm version: 3.10.10 Node version: v6.11.1

Fact is, manually it's working fine. Dragging the file and clicking on Upload button, is uploading the document.

Could anyone help me resolving this issue.

One more thing I would like to add, I tried giving sleep in protractor script and perform upload action manually and it was working fine. I think it's not counting the upload document as correct file or file itself.

Upvotes: 0

Views: 63

Answers (2)

Xotabu4
Xotabu4

Reputation: 3091

Probably, if you are running on remote machine (like selenium grid or selenoid, or inside container) you will need to use FileDetector, i prepared small script here, to demonstrate:

https://gist.github.com/Xotabu4/13c81465e959974429e2bba9a3408b71

This code will actually send your file over http to machine where browser is located

Upvotes: 0

Anchal Singh
Anchal Singh

Reputation: 362

Try this:

    const path = require('path');
    const fileToUpload = '../image/dummy.jpg'; // image folder is present in e2e folder of angular project
    const absolutePath = path.resolve(__dirname, fileToUpload);
    const fileElem = element(by.css('input[type="file"]'));
    fileElem.sendKeys(absolutePath);

Upvotes: 0

Related Questions