如何使用Robot Framework在Chrome浏览器中自动下载pdf文件 [英] How to download a pdf file automatically in chrome browser using Robot Framework

查看:360
本文介绍了如何使用Robot Framework在Chrome浏览器中自动下载pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为测试的一部分,我希望在加载到浏览器后自动从浏览器自动下载pdf文件.有人可以指导我如何实现.以下是我尝试的方式.我尝试单击下载按钮,但对我而言不起作用.以下是显示在浏览器上的屏幕截图.

As a part of my test , i want to download a pdf file from browser automatically as soon as it loads on browser. Can someone guide me how this can be achieved.Following is the way that i have tried.I have tried clicking the download button but it didn't work for me. Following is the screenshot that appears on browser .

*** Test Cases ***

    Download and deploy content package 

        ${output}=   Run keyword   job history
        Log to console   ${output}
        # 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
        ${prefs}    Create Dictionary    prompt_for_download=false  download.default_directory=${download directory}    
        Call Method    ${chrome options}    add_experimental_option    prefs    ${prefs}
        Create Webdriver    Chrome    chrome_options=${chrome options}
        Goto   ${output}   
        Sleep       5

推荐答案

对于文件下载,我有非常简单的解决方法.它具有以下规则:

I have quite simple workaround for file downloads. It has following rules:

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

  • Create download folder in suite setup

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}

  • 清除测试拆解中的文件夹

  • Clear the folder on test teardown

    Run Keyword And Ignore Error    Empty Directory    ${global_downloadDir}
    

    有了上面的内容,您将可以轻松操纵下载的文件.

    With above, you'll be easily able to manipulate downloaded files.

    这篇关于如何使用Robot Framework在Chrome浏览器中自动下载pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆