How do you check that a browser download has finished before opening the file?

I’m designing a Browser-library check for a page that exports an image. The test needs to click Download and then open the resulting file. A file from an earlier run could have the same name, so finding that name in the download directory would be a weak check.

My intended sequence is to start listening for the download before clicking, use a fresh destination for the current run, and then try to decode the file. I’d like to keep the failure messages separate so a timeout waiting for the download looks different from an unreadable image.

Where do you draw that line in Robot Framework Browser? Is there a download keyword or result you rely on for completion before the image check starts? If you have a small example that handles a repeated filename, I’d be interested in how you set up the destination and which step reports a failed download.

Hi Amelia,

Welcome to the community,

I would suggest to use Get Time keyword from the BuiltIn library to generate a timestamp variable, use that in the as part of the saveAs argument to the Download keyword from Browser Library to control the file name of the file that’s downloaded, then your can search for the filename with that timestamp.

I don’t have a working example but I expect it would look something like this:

*** Settings ***
Library    Browser
Library    BuiltIn
Library    OperatingSystem

*** Tests ***
Check Image Download
    ${imgurl} =    Get Attribute   #your_img    href 
    ${timestamp} =    Get Time    epoch
    Download    ${imgurl}    saveAs=${OUTPUT DIR}/downloads/imagename_${timestamp}.png
    File Should Not Exist    ${OUTPUT DIR}/downloads/imagename_${timestamp}.png

I just typed that example based on the docs so you may need to tweak it but it should be close to what you’re after.

Dave.