22

I am writting a protractor test case to download a file which can be of any type.

  • Scenario: Download a file
  • Step 1: Click on the Download Link
  • Step 2: Check whether the file is downloaded or not

How do i check if the file is downloaded correctly or not?

Nekvin
  • 83
  • 1
  • 11
Hmahwish
  • 2,222
  • 8
  • 26
  • 45

1 Answers1

28

I was able to achieve download testing with Chrome.

  1. Follow this config setup: https://stackoverflow.com/a/26127745/511069

  2. Create a function waitFileExists(fileAbsPath) and performs your expectations after the file is completely downloaded: https://stackoverflow.com/a/27031924/511069

Leo Gallucci
  • 16,355
  • 12
  • 77
  • 110
  • hi @Leo Gallucci , i changed something to download excel and pdf. It worked for exporting excel file but falsed with pdf. I think "application/pdf" is not enough to set download automatically pdf file. What can I do ? – AquariusPotter Sep 09 '19 at 09:37
  • 1
    @AquariusPotter You need to add the content disposition header for that, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition – alexrogers Feb 26 '20 at 14:10
  • Sample code for an Angular/TypeScript project: https://gist.github.com/tw3/ef2858f3fe4d224e02eb9ff5dbca2aba – tedw Feb 29 '20 at 00:43
  • 2
    Thank you! You saved me hours of investigating. – José Manuel Blasco Mar 03 '20 at 11:01