1

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:

  1. Click link to upload doc
  2. Modal is displayed with Browse button to select (Modal Image)
  3. Browse button must be used to browse for the file - cannot insert into 'text box'
  4. Select a date using calendar tool
  5. Submit button then becomes active
  6. Click Submit and can proceed through app process

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?

a. Lewis
  • 11
  • 2
  • what is findInput() doing? Does it locate the input element? If you look at your Modal does it contain a hidden field to upload a document. Thats the element you need to do a sendKeys to. – Simon N Jan 08 '19 at 04:21
  • paste the html of the modal so I can see... – Simon N Jan 08 '19 at 04:23
  • Hi Simon - thanks for the response. findInput() is simply locating the input element. I think you are right in that in the modal there is a hidden field...I am unable to share the html b/c of the sensitive nature of the work. – a. Lewis Jan 09 '19 at 22:19

1 Answers1

0

Answer Found Here

functioning code below:

uploadDoc() {
return browser.findElement(by.css('input[type=file]')).sendKeys('full/path/of/the file/with.extension');
}
a. Lewis
  • 11
  • 2