2016-02-09 11 views
7

मैं रोबोट फ्रेमवर्क का उपयोग करें।रोबोट फ्रेमवर्क फ़ाइल डाउनलोड

मेरी HTML पृष्ठ पर मैं एक साधारण बटन होता है। जब आप उस पर क्लिक करते हैं, तो यह एक पीडीएफ फ़ाइल डाउनलोड करता है।

मैं रोबोट फ्रेमवर्क के साथ जांच कैसे करूं कि फ़ाइल डाउनलोड किया गया है?

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

मैं क्रोम का उपयोग कर रहा हूँ। – Raphael

उत्तर

10

समाधान बहुत ब्राउज़र विशिष्ट है:

Tks

मैं ombre42 एक समाधान, @ करने के लिए टी.के.एस पाया। क्रोम के लिए, आप क्रोम को फाइल कहां डाउनलोड कर सकते हैं। एक नया फ़ोल्डर चुनने से आप डाउनलोड की स्थिति की निगरानी कर सकते हैं। साथ ही, चूंकि आप एक पीडीएफ डाउनलोड कर रहे हैं, पीडीएफ प्लगइन को अक्षम करना पीडीएफ को डाउनलोड किए जाने के बजाय प्रदर्शित होने से रोकने के लिए आवश्यक है। यहां एक परीक्षण है जो एक सरल पृष्ठ और पीडीएफ फाइल का उपयोग करके मेरी मशीन पर काम करता है।

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

download.html की सामग्री: - डाउनलोड करने से पहले और डाउनलोड करने के बाद

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

आईई ऐसा करना संभव है? – user2520217

0

आप फ़ाइल का MD5 जाँच करने के लिए की जरूरत है। दोनों एमडी 5 समान होना चाहिए।

मान लिया जाये कि फ़ाइल Linux मशीन पर है - पहले और डाउनलोड करने के बाद: # md5sum PATH_TO_FILE

  • स्टोर एक चर में उत्पादन:

    1. लॉग इन linux मशीन SSH पुस्तकालय
    2. भागो आदेश का उपयोग करने के लिए।
    3. चर मूल्य की तुलना करें

    आशा तो यह जानकारी सहायक रही।

  • संबंधित मुद्दे