2016-02-09 13 views
7

Ich benutze Robot Framework.Robot Framework Download Datei

Auf meiner HTML-Seite habe ich eine einfache Schaltfläche. Wenn Sie darauf klicken, wird eine PDF-Datei heruntergeladen.

Wie kann ich mit Robot Framework überprüfen, ob die Datei heruntergeladen wurde?

Tks

fand ich eine Lösung, tks zu @ ombre42:

${SERVER}     ${SERVER_DEV} 
${NAME}     Robot 
${FILE_NAME}    Robot.pdf 
${CLASS_NAME}    in 
${DOWNLOAD_DIRECTORY}  C:\\robot_download 

Scenario: User can download 
    Create Directory ${DOWNLOAD_DIRECTORY} 
    ${CHROME_OPTIONS}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver 
    ${disabled} Create List  Chrome PDF Viewer 
    ${prefs} Create Dictionary download.default_directory=${DOWNLOAD_DIRECTORY} plugins.plugins_disabled=${disabled} 
    Call Method ${CHROME_OPTIONS} add_experimental_option prefs ${prefs} 
    Create Webdriver Chrome chrome_options=${CHROME_OPTIONS} 
    Goto ${SERVER} 
    Click Element ${NAME} 
    Wait Until Element Is Visible css=div.${CLASS_NAME} 8 
    Page Should Contain ${NAME} 
    Set Selenium Speed 10s 
    Download PDF ${NAME} 
    File Should Exist C:\\robot_download\\${FILE_NAME} 
+0

Welchen Browser benutzen Sie? – ombre42

+0

Ich verwende Chrome. – Raphael

Antwort

10

Die Lösung sehr Browser spezifisch ist. In Chrome können Sie Chrome mitteilen, wo es Dateien herunterladen soll. Wenn Sie einen neuen Ordner auswählen, können Sie den Status des Downloads überwachen. Da Sie eine PDF-Datei herunterladen, muss das PDF-Plug-in deaktiviert werden, damit die PDF-Datei nicht heruntergeladen, sondern angezeigt wird. Hier ist ein Test, der auf meinem Rechner mit einer einfachen Seite und einer PDF-Datei funktioniert.

*** Settings *** 
Test Teardown  Close All Browsers 
Library   Selenium2Library 
Library   OperatingSystem 

*** Test Cases *** 
Download PDF 
    # create unique folder 
    ${now} Get Time epoch 
    ${download directory} Join Path ${OUTPUT DIR} downloads_${now} 
    Create Directory ${download directory} 
    ${chrome options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver 
    # list of plugins to disable. disabling PDF Viewer is necessary so that PDFs are saved rather than displayed 
    ${disabled} Create List Chrome PDF Viewer 
    ${prefs} Create Dictionary download.default_directory=${download directory} plugins.plugins_disabled=${disabled} 
    Call Method ${chrome options} add_experimental_option prefs ${prefs} 
    Create Webdriver Chrome chrome_options=${chrome options} 
    Goto http://localhost/download.html 
    Click Link link # downloads a file 
    # wait for download to finish 
    ${file} Wait Until Keyword Succeeds 1 min 2 sec Download should be done ${download directory} 

*** Keywords *** 
Download should be done 
    [Arguments] ${directory} 
    [Documentation] Verifies that the directory has only one folder and it is not a temp file. 
    ... 
    ... Returns path to the file 
    ${files} List Files In Directory ${directory} 
    Length Should Be ${files} 1 Should be only one file in the download folder 
    Should Not Match Regexp ${files[0]} (?i).*\\.tmp Chrome is still downloading a file 
    ${file} Join Path ${directory} ${files[0]} 
    Log File was successfully downloaded to ${file} 
    [Return] ${file} 

Inhalt von download.html:

<html><body><a href="file.pdf" id="link">Click Here</a></body></html> 
+0

IE ist möglich, das zu tun? – user2520217

0

Sie müssen die MD5 der Datei überprüfen - vor dem Download und nach dem Download. Beide MD5 sollte gleich sein.

Angenommen Datei ist auf Linux-Maschine - vor und nach dem Download:

  1. Login Linux-Rechner mit SSH Bibliothek
  2. Führen Sie den Befehl: # md5sum PATH_TO_FILE
  3. Speichern Sie die Ausgabe in einer Variablen.
  4. Vergleichen Sie die Variablenwert

Hoffnung so diese Informationen hilfreich war.

Verwandte Themen