Downloading a file and verify that file was successfully downloaded

3,105 views
Skip to first unread message

antonio III cabreira

unread,
Oct 25, 2012, 9:51:55 AM10/25/12
to robotframe...@googlegroups.com
Hi,

Here's the scenario, I need to download a file from a web application and then I have to verify that it was successfully downloaded by locating the downloaded file in my Windows operated machine. Is there a library that could do this in robot framework? 

Thanks!

Hi-Fi

unread,
Oct 26, 2012, 12:38:57 AM10/26/12
to robotframe...@googlegroups.com
Not directly. I have used Wget myself, where downloading can be handled with keyword (for pages that need credentials, so getting the JSESSION (at this case) from cookie and using it.:
Download a file
    [Arguments]    ${cookie}    ${URL}    ${outputName}
    ${cookieValue} =    Get Cookie Value    ${cookie}
    ${outputDir} =    Set Variable    ${EMPTY}
    ${rc}    ${output}    Run And Return Rc And Output    wget --cookies=on --header "Cookie: ${cookie}=${cookieValue}" -O ${outputName} ${URL}
    Log    ${rc}
    Log    ${output}
    Move File    ${outputName}    /tmp/

Hi-Fi

unread,
Oct 30, 2012, 3:25:13 AM10/30/12
to robotframe...@googlegroups.com
And some improvement; this creates the file always, even wget return error / some other code than 200.

So what's needed is to count lines containing error / parse response from server code. 

That can be done directly with grep (when ${output} can be used direcly), or with the help of String -library (which helps if tests needs to be run eg. in windows, where grep isn't present).

So basivcally new keyword:
Get line count containing string
    [Arguments]    ${string}    ${match}
    ${lines} =     Get Lines Containing String    ${string}    ${match}
    ${lineCount} =     Get Line Count    ${lines}
    [Return]    ${lineCount}


And checking lineCount (if >0, fail the test).

Br,
Juho
Reply all
Reply to author
Forward
0 new messages