0

How to create the profile for Internet explorer in protractor for automatic download files.

I found for Chrome and Firefox but I could not find it for internet explorer

Reference: Protractor e2e test case for downloading pdf file

Thanks

Community
  • 1
  • 1

1 Answers1

0

While this doesn't answer your question directly, here is a link to an excellent blog about "How to download files with selenium and why you should not". Author talks about different use cases and provides a back door solution to do this in Java. The most critical question the article mentions is

"What are you going to do with this downloaded file?"

"Do you want to just makes sure that you get 200 OK from the server?"

"Do you want to verify the content?"

Obviously mostly people would say "yes" to "200 OK verification", If you want to validate the content of lets a PDF document, then its outside the scope of selenium anyways. The article provides Java solution to check if you get 200 OK from the server, Since you are using protractor, I'll provide a nodejs solution.

var request = require('request');
var fileDownloadElement = element(by.css('#download'));
fileDownloadElement.getAttribute('href').then(function(url) {
    request(url,function(error, response, body){
        if(error) {
          throw new Error('Error downloading file', error);
        }
        if(response.statusCode !== 200) {
           throw new Error('Server threw non 200 OK status ->', response.statusCode);
        }
        if(!body) {
            throw new Error('Server did not respond with any data');
        } else {
           //write body to a file if you want to do anything with it
        }
    });
});

I used request client up here, you can use it or any other similar client.

Disclaimer: I haven't tested this code, but hope you get the idea.

Community
  • 1
  • 1
nilesh
  • 14,131
  • 7
  • 65
  • 79