2016-02-09 22 views
7

私はRobot Frameworkを使用しています。Robot Frameworkダウンロードファイル

私のHTMLページには、単純なボタンがあります。あなたがそれをクリックすると、pdfファイルがダウンロードされます。

ファイルがダウンロードされている場合、どうすればRobot Frameworkで確認できますか?

TKS

は、私は@ ombre42に対する解決策、TKSが見つかりました:

${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

お使いのブラウザはどちらですか? – ombre42

+0

私はChromeを使用しています。 – Raphael

答えて

10

ソリューションは非常にブラウザ固有のものです。 Chromeの場合、Chromeにファイルのダウンロード先を伝えることができます。新しいフォルダを選択すると、ダウンロードのステータスを監視できます。また、PDFをダウンロードしているので、ダウンロードされずにPDFが表示されないようにするには、PDFプラグインを無効にする必要があります。ここでは、単純なページとPDFファイルを使用して自分のマシンで動作するテストを示します。 download.htmlの

*** 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} 

内容:

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

IEが可能ですか? – user2520217

0

あなたは、ファイルのMD5をチェックする必要があります - ダウンロードする前に、ダウンロードした後。 両方のMD5が同じである必要があります。

と仮定すると、ファイルは、Linuxマシン上で - 前とダウンロード後:#1のmd5sum PATH_TO_FILE

  • ストア変数で出力:

    1. ログインSSHライブラリー
    2. 実行]コマンドを使用してLinuxマシンに。
    3. ので、この情報は役立ちましたホープ・変数値

    を比較。

  • 関連する問題