3

In my test scenario i do click on a link present in my webpage using selenium web driver and this click action initiate downloading a file to the computer...... In this flow it do not open any window asking where to save the file and it saves to the default download folder..so it is fine...

Now my objective is to test/verify this download process happened or not using WebDriver Selenies commands it self ...? So basically an assertion method required for the download ... Am doing this in Chrome browser Can any one please share how can we do this

Thanks in Advance Musaffir

Akbar
  • 1,513
  • 4
  • 20
  • 34
Traveller87
  • 151
  • 1
  • 6
  • 11

4 Answers4

0

You can use regular Java file object functions to verify if a file is present in a particular folder or not. How do I check if a file exists in Java?

Community
  • 1
  • 1
Akbar
  • 1,513
  • 4
  • 20
  • 34
  • Hello TestAutomationEngr, This is possible if we are aware of the file name...we can check it whether the same file is in the folder or not...For scenarios like when we do not even aware of wat file it generates when we click on the link, or when it genrates random file name ...what approach would be best here....am looking for sloution to this problem... Thanks for your time .... – Traveller87 Sep 20 '13 at 09:58
  • That makes it interesting....cannot think of anything currently...will post if anything comes to mind. BTW you should tell your developers to show the name of the file on the webpage. It should not be too much of work for them... – Akbar Sep 20 '13 at 10:43
0

Empty your download folder after each test run. You want a clean tidy test server anyway. Then the test will result in exactly one file in your download folder.

If you need your test to run on another machine where you cannot clear the folder, you'll have to temporarily rename the folder or temporarily change the setting for Chrome to use a different folder.

Colin Pickard
  • 45,724
  • 13
  • 98
  • 148
0

You can get the latest downloaded file from folder using File System and then retrieve the details of file (such as name)

NamrataH
  • 3
  • 1
0

First clear the configured download directory and check for the file exists with file name in the directory, put a do while loop to check until file exists in the folder also mentioned the number of maximum iteration to wait else if any problem in file downloading then the loop won’t break.