Fury
Fury

Reputation: 142

Unable to upload a file through protractor?

I am practicing on uploading a file through protractor in this particular web application: https://www.fileconvoy.com/

beacuse, when I get my angular web application I need to automate the upload functionality.

I am unable to upload the file and its throwing error like below:

VError: a BeforeAll hook errored, process exiting: typeScript\support\hooks.js:14: function timed out, ensure the promise resolves within 100000 milliseconds

I tried the below suggested options in SO but all in vain:

1).Running the autoit.exe code and whenever that window pop-up it'll directly provide the path. 2).through sendKeys

3).Through the below code:

    var ele=element(by.xpath("//input[@type='file']"));
    //await browser.wait(EC.elementToBeClickable(ele),1500);
    ele.click();
    var path = require('path');
    var fileToUpload = '../file/Capture001.png',
    absolutePath = path.resolve(__dirname, fileToUpload);
    await ele.sendKeys(absolutePath);

I am new to protractor so require some help.Can anyone suggest me some working code on how to fix this? Thank you.

Project folder structure

Upvotes: 1

Views: 814

Answers (1)

Majesty
Majesty

Reputation: 1909

This one works for me, no need for click event:

var ele = element(by.xpath("//input[@type='file']"));
const absolutePath = path.resolve(__dirname, './../../file/Capture001.png');
await ele.sendKeys(absolutePath);

P.S. using xpath selectors is NOT recommended, consider other selector strategies.

Upvotes: 2

Related Questions