How to validate the download of files using Selenium Webdriver?

Asked

Viewed 1,007 times

1

Hello, I wrote an automation test on the Selenium Webdriver using C#, and one of the steps requires downloading an XLSX file from the server.

How can I validate whether the file has been successfully downloaded and get its name?

1 answer

1

There are several ways to validate whether the file is intact. One way to validate is to take the checksum CRC32 of the file BEFORE and validate the file you downloaded and compare the values.

On Linux, the command is

cksum arquivo.txt

The exit will be

linux@ubuntu:~$ cksum arquivo.txt
3474990042 214 arquivo.txt

Where the first code is the CRC32 file, the second is the number of bytes and the third is the file name.

Another, which I particularly like best, is to use the Md5sum of the file, as follows:

linux@ubuntu:~$ md5sum arquivo.txt

and the answer will be

cbc8ccd6c7f5a111f494cfd4e0aea86e  arquivo.txt

where the first column will be the MD5 hash of the file and the second, the name of the file itself.


  • The file that Selenium tests the download is dynamic, and I am in Microsoft environments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.