protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Protractor File upload failing with ng upload version 3.3.4

Open snehacharkha opened this issue 11 years ago • 13 comments

I have been using the usual file upload in the protractor to upload the files .

element(by.id('upload_button')).sendKeys('file path');

It was working fine until our application's 'ng upload' upgraded to version 3.3.4.

We are using protractor Version 1.4.0.

Is this a known issue ?? Does anyone know a workaround for this

snehacharkha avatar Apr 30 '15 21:04 snehacharkha

Are you referring to https://github.com/twilson63/ngUpload? In any case, I can't find an ng-upload with version 3.3.4. Can you post a link to which library you're using?

Additionally, please update protractor to the latest version first. There has been numerous bug fixes since then which would already have solved your issue.

hankduan avatar May 01 '15 18:05 hankduan

https://github.com/danialfarid/ng-file-upload

Above is the link to ng-file upload . We will upgrade our protractor and try

snehacharkha avatar May 01 '15 19:05 snehacharkha

We tried same thing with Protractor 2.0 . It dint work

snehacharkha avatar May 01 '15 21:05 snehacharkha

I encountered this as well.

It worked with protractor 1.6.1 and ng-file-upload 3.0.7

Then after we upgraded to ng-file-upload to 4.1.0 it stopped working with both Protractor 1.6.1 and Protractor 2.0.

Weird thing is that it works on Internet Explorer 11 :dizzy_face:

tzclucian avatar May 04 '15 15:05 tzclucian

I can't tell you exactly what is wrong without seeing your app. However, I wrote a test against ng-file-upload's demo site (http://ngupload.herokuapp.com/) and it works fine. I'm assuming they're using the latest version of their library for the demo.

Here's the test:

  it('should upload', function() {
    browser.get('http://ngupload.herokuapp.com/');
    var filePath = '/Users/hankduan/testfile';
    $('#foo').$$('input[type="file"]').sendKeys(filePath);
    $('#foo').$$('input[type="submit"]').click();
    var info = $$('.alert-info').first().$('.ng-binding');
    expect(info.getText()).toContain('"testfile" uploaded to the server');
  });

In your conf file, make sure you add rootElement: '[ng-app]' since their root element is not body.

Can you provide a reproducible test case (i.e. against a public app) to debug further?

hankduan avatar May 04 '15 19:05 hankduan

Hey @hankduan ,

Are you sure http://ngupload.herokuapp.com/ is using https://github.com/danialfarid/ng-file-upload?

I have ran the same test you have written and it works with the same configuration that I use inside our app. Therefor I believe the app is using either another upload method (https://github.com/twilson63/ngUpload) either an older version of the https://github.com/danialfarid/ng-file-upload.

I have also ran the same test on this page https://angular-file-upload.appspot.com/ on this element:

element(by.css("fieldset>div[ng-model='files']")); (the element with the caption: "Drop Images or PDFs click to select") and the upload fails with:

The error that I get is below:

UnknownError: unknown error: cannot focus element

(Session info: chrome=42.0.2311.135) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Mac OS X 10.10.3 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 25 milliseconds Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50' System info: host: '', ip: '_', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.8.0_31' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/pr/20nj2cvj51b6s502xb3rl39wv082p4/T/.org.chromium.Chromium.a8bg4Z}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=42.0.2311.135, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: ac1d8fe8ee09fb78fad1b42ecb47bf69

Thanks!

PS: I see this issue is also present here: https://github.com/danialfarid/ng-file-upload/issues/710

tzclucian avatar May 06 '15 16:05 tzclucian

hi @hankduan,

What do you mean by "In your conf file, make sure you add rootElement: '[ng-app]' since their root element is not body."

Can you send your conf file ?

Thanks.

prabhu-telsiz avatar May 06 '15 17:05 prabhu-telsiz

Im using something like this.

HTML: input type="file" name="vedgeImage" class="pull-left" data-ng-model="fileVedge" multiple="false" accept=".bz2" data-ng-file-select data-ng-click="vedgeFileSelect()" id="vedge_file_select"

Protractor:

  1. element(by.id("vedge_file_select")).sendKeys(filepath); (This line of code works properly fine.It browses for file from the path given)

  2. When i click upload button "required error" message is thrown. It thinks that no file is selected element(by.id("Upload")).Click();

These are the same lines of code I used before upgrading ng-upload to version 3.3.4. It was working fine. After upgrading ng-upload to version 3.3.4, the same lines of protractor code doesnt work.

NOTE : BUT IF I DO THIS MANUALLY-( BROWSE AND UPLOAD OPERATION) IS TOTALLY FINE. IT SEEMS TO BE BROKEN WHEN PERFORMNG THE SAME OPERATION WITH PROTRACTOR.

prabhu-telsiz avatar May 06 '15 17:05 prabhu-telsiz

@prabhu-telsiz In your conf file you can specify the html element that has the ng-app directive. By default it is set to body.

But as @hankduan said http://ngupload.herokuapp.com/ doesn't have the directive on the body element so you must specify it in the conf file. Simply add: rootElement : "[ng-app]".

tzclucian avatar May 06 '15 18:05 tzclucian

Thanks @tzclucian

I modified my protractor conf.js file. I have added rootElement : "[ng-app]". This is how my conf.js.

var env = require("/baseOptions.js"); var onPrep = require("/onPrepare.js"); exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['/Users/prabhu/software_repository_proper_image.spec.js'], rootElement : "[ng-app]", baseUrl: env.baseUrl, multiCapabilities:[ { 'browserName': 'chrome', 'version': 'ANY', 'loggingPrefs': { 'browser': 'ALL' } } ], baseUrl: env.baseUrl, onPrepare: onPrep.onPrepare, jasmineNodeOpts: env.jasmineNodeOpts }

I ran the protractor test and I see the same issue again. What happens is it browses the file and when I click upload, it thinks there is no file.

Also I get the same error as mentioned by tzclucian .

Error:

UnknownError: unknown error: [ng:test] http://errors.angularjs.org/1.3.13/ng/test (Session info: chrome=42.0.2311.135) (Driver info: chromedriver=2.12.301326 (093c7e07b4a916b690e784b0374c7f618f1ea4be),platform=Mac OS X 10.9.5 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 5 milliseconds Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37' System info: host: 'Prabhu-MacBookPro.local', ip: '192.168.20.67', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.5', java.version: '1.8.0_25' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={userDataDir=/var/folders/p4/vzr14mln5fjbbck3rmsr52bc0000gq/T/.org.chromium.Chromium.CpWzHz}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=42.0.2311.135, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 72aa6a4fc554b1e20ae1440afa9dd728

ScreenShot :

screen shot 2015-05-06 at 1 56 05 pm

prabhu-telsiz avatar May 06 '15 21:05 prabhu-telsiz

Any updates or atleast workarounds for this issue?

tzclucian avatar May 19 '15 15:05 tzclucian

I had the same issue. Same thing: worked fine when I dragged the file from my file system but didn't work in protractor test.

My code is in /projects/... e.g. not in my User's directory

I moved the file to my desktop (within User's directory) and changed the absolute path. Test worked.

ghost avatar Sep 07 '15 21:09 ghost

Closing as this is specific to ng-upload, and this issue has gotten messy so I'm not even sure exactly what problems are still present.

Please open up a new, clean issue with a reproducible test case if you are still experiencing a problem. Thanks!

juliemr avatar Jul 14 '16 18:07 juliemr