0

I have a selenium test to check if a downloaded file is the correct one, so I want to check if the exported file does not have records on it, only the columns and a message saying "There are no results on this exported file..."

It is enough to use the hash value to validate the file content?

msiles
  • 657
  • 3
  • 10
  • 19
  • Why don't you just check if the file size is 0? http://stackoverflow.com/questions/8721262/how-to-get-file-size-in-java – martingreber May 25 '16 at 23:35
  • @martingreber because there are some columns and message saying there are not records on this report. – msiles May 25 '16 at 23:36
  • Ok, maybe include a bit more detail about your specific case and maybe update the subject. It seemed like you just wanted to check if a file is empty, but I suppose there's more to it. BTW, to answer the original question, yes you can use the hash. Just hash the file contents. The result will always* be the same if the input is the same. (*of course, there are limitations to any hash algorithm) – martingreber May 25 '16 at 23:45
  • An hash would tell that the file is **probably** ok. Hash can sometime be ok even though the file is bad. – Phil1970 May 26 '16 at 00:48

3 Answers3

1

Note that two files with different content could sometimes produce the same hash due to hash collision

foo
  • 157
  • 1
  • 1
  • 11
1

Using hashes to check your files are downloading okay is probably fine, depending on the hashing algorithm you use. While hash collisions are possible with for example md5 I do not think this is very likely. Many sites still use md5 checksums as a way to verify file integrity on downloads.

Mobrockers
  • 2,128
  • 1
  • 16
  • 28
0

I found an example from Selenium Easy.

This https://www.seleniumeasy.com/selenium-tutorials/verify-file-after-downloading-using-webdriver-java might just be what you are looking for.