2

I would like to know why testing the upload file (with absolutePath) works fine but it doesn't close the file selection dialog.

This is my code:

var path = require('path');
it('Upload file', function() {
  var button = element(by.css('button')).click();
  expect(button.isEnabled()).toBe(true);
  var test= ['../file/1.pdf','../file/2.pdf','../file/3.pdf'];
  for (var i=0;i<test.length;i++)
  {
  var absolutePath = path.resolve(__dirname, test[i]);
  element(by.css('input[type="file"]')).sendKeys(absolutePath);
  element(by.buttonText("Submit")).click(); 
  }
  element.all(by.css('span[ng-show="upload.complete"]')).each(function(complete){
    var text = complete.getText();
  expect(text).toEqual("Upload Complete");
});

Thank you in advance!

ZaitseV
  • 179
  • 2
  • 14

1 Answers1

2

You can't control windows dialog boxes with Protractor since it uses webdriver.

The code above will not enter the file path into the windows dialog box but rather it is sending the absolute file path directly to the file upload element on the page. Thus you don't need to open the windows dialog box at all to upload a file.

If you are interested in interacting with windows dialogs there are some packages that could help you such as https://github.com/octalmage/robotjs

KCaradonna
  • 760
  • 6
  • 13