4

I have a project that has Protractor tests which are executed by TravisCI via SauceLabs.

One of the tests involve "uploading" a file:

it('should not allow "image/jpeg" file', function () {
  pathToFile = path.resolve(__dirname, 'file.jpg');
  elem.sendKeys(pathToFile);
  expect(elem.getAttribute('class')).toMatch('ng-invalid');
});

This works fine locally, however Travis produces an error:

. . . ./file.jpg' does not exist on the file system

I think this is because file.png doesn't exist on SauceLabs.

My question is, how can I get this to work?

The directive in question is this one: https://github.com/GrumpyWizards/ngValidation/blob/master/wizValidation/src/file/file.dir.js

Greg
  • 30,678
  • 16
  • 63
  • 84
  • Can you give a bit more information on the element/directive you're testing? – Michal Charemza May 03 '14 at 18:58
  • Updated the question... – Greg May 04 '14 at 20:08
  • 2
    Looks like there is a function `setFileDetector`, explained at http://saucelabs.com/resources/selenium-file-upload, that can theoretically get this working. However, from https://github.com/angular/protractor/issues/612 and https://code.google.com/p/selenium/issues/detail?id=6048#c3 , it looks like at the moment, there isn't a Node binding, and so won't be accessible from Protractor until it's added (or you add it: but I'm not sure if you can use a custom build of Selenium with Sauce?) – Michal Charemza May 05 '14 at 11:44
  • Same issue with my plugin here: http://ng-form-data.tomchentw.com/ – Tom Chen May 07 '14 at 18:59
  • I got the same conclusion for Michal's comment here. – Tom Chen May 07 '14 at 19:00

1 Answers1

0

It's a UI test, there is no need to resolve a path name at all...

it('should not allow "image/jpeg" file', function () {
  pathToFile = "path/is/not/important/file.jpg";
  elem.sendKeys(pathToFile);
  expect(elem.getAttribute('class')).toMatch('ng-invalid');
});

Michael

Michael Dausmann
  • 3,448
  • 2
  • 27
  • 39