如何使用Robot Framework在chrome浏览器中自动下载pdf文件

时间:2017-05-24 11:15:21

标签: pdf robotframework selenium2library

作为测试的一部分,我想在浏览器上加载后立即自动从浏览器下载pdf文件。有人可以指导我如何实现这一点。以下是我试过的方式。我试过点击下载按钮但它对我没有用。以下是浏览器上显示的屏幕截图。enter image description here

<IfModule mod_ssl.c>
    <VirtualHost *:8181>
        ServerAdmin webmaster@example.com
        ServerName www.example.com
        ServerAlias example.com
        DocumentRoot /var/www/example.com
        <Directory /var/www/example.com>
            Options FollowSymLinks
            AllowOverride All
            Allow from all
            AuthUserFile /var/.htpasswd
            AuthName "AUTHENTIFICATION"
            AuthType Basic
            <Limit GET POST>
                Require valid-user
            </Limit>
        </Directory>

        ServerSignature Off 
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    </VirtualHost>
</IfModule>

2 个答案:

答案 0 :(得分:2)

我有一个非常简单的文件下载解决方法。它有以下规则:

  • 在套件设置中创建下载文件夹

    Set Global Variable    ${global_downloadDir}    ${CURDIR}\\Downloads\\${suite_orgName}
    ${chromeOptions}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    ${prefs} =    Create Dictionary    download.default_directory=${global_downloadDir}
    Call Method    ${chromeOptions}    add_experimental_option    prefs    ${prefs}
    Create Webdriver    Chrome    chrome_options=${chromeOptions}
    
  • 清除测试拆解文件夹

    Run Keyword And Ignore Error    Empty Directory    ${global_downloadDir}
    

    通过上述内容,您可以轻松操作下载的文件。

答案 1 :(得分:0)

虽然上面的答案很好,但对我来说代码有效。

Conference Summary
     ${output}=   Run keyword   SLO conformance summary
    # create unique folder in current directory
    ${current_date}=    Get Current Date 
    ${folder_name} =    Convert Date    ${current_date}    result_format=${SUITE NAME}.%d.%m.%Y_%H.%M
    ${download directory}    Join Path    ${OUTPUT DIR}    ${folder_name}
    Create Directory    ${download directory}
    ${options}  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
    Call Method  ${options}  add_argument  --start-maximized
    ${preferences} =    Create Dictionary   prompt_for_download=false  download.default_directory=${download directory}    download.directory_update=True
    Call Method  ${options}  add_experimental_option  prefs  ${preferences}
     Create WebDriver  Chrome  chrome_options=${options} 
    Go To    ${output}     
    sleep   4
    Page Should Not Contain Element  //div[@class='errorIcon']
    Run Keyword     Get export position