I am currently using protractor to validate a user's walk through a Web App. To proceed (buttons are disabled until an action is performed) a user must upload a document, which then enables buttons to be pressed and would then proceed with the process.
In my local code I have a folder that contains the document needed to be uploaded to proceed. However, when I am interacting with the web app via protractor, I am struggling with getting it uploaded.
As it works now:
I have attempted the solution here: How to upload file in angularjs e2e protractor testing , but the issue is that the 'text area' to insert the path into returns an 'Invalid Element State Error' - I cannot simply insert the path into the box as the solution above seems to suggest.
Bottom line is I need to upload this document while necessarily using the browse button, but I cannot use protractor to manipulate the local dialogue box used to browse the machine.
My code:
it('should upload the example doc', function() {
var path = require('path');
var fileToUpload = 'path/path/path/',
absolutePath = path.resolve(__dirname, fileToUpload);
page.findInput().sendKeys(absolutePath);
browser.sleep(3000);
expect(page.submitBtnClick());
});
Thoughts?
functioning code below:
uploadDoc() {
return browser.findElement(by.css('input[type=file]')).sendKeys('full/path/of/the file/with.extension');
}