I want to test file uploading using an angularjs e2e test. How do you do this in e2e tests? I run my test script through grunt karma.
But, according to webdriver:upload multiple files, you should be able to solve it in Chrome by joining file paths with a new-line character: uploadInput. sendKeys(absolutePath1 + "\n" + absolutePath2);
Angular Team Announces End of Protractor Development By continuing to use Protractor, users may end up with disruptions in their automation scripts. However, the Protractor team has defined a timeline that gives users enough time to look into alternatives and migrate their tests accordingly.
This is how I do it:
var path = require('path'); it('should upload a file', function() { var fileToUpload = '../some/path/foo.txt', absolutePath = path.resolve(__dirname, fileToUpload); element(by.css('input[type="file"]')).sendKeys(absolutePath); element(by.id('uploadButton')).click(); });
path
module to resolve the full path of the file that you want to upload.This will not work on firefox. Protractor will complain because the element is not visible. To upload in firefox you need to make the input visible. This is what I do:
browser.executeAsyncScript(function(callback) { // You can use any other selector document.querySelectorAll('#input-file-element')[0] .style.display = 'inline'; callback(); }); // Now you can upload. $('input[type="file"]').sendKeys(absolutePath); $('#uploadButton').click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With