如何使用 Robot Framework 在 chrome 浏览器中自动下载 pdf 文件
How to download a pdf file automatically in chrome browser using Robot Framework
作为我测试的一部分,我想在浏览器加载 pdf 文件后立即自动从浏览器下载它。谁能指导我这是怎么回事 achieved.Following 是我 tried.I 尝试点击下载按钮的方式,但它对我不起作用。以下是在浏览器上显示的屏幕截图。
*** 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
我有一个非常简单的文件下载解决方法。它有以下规则:
在套件设置中创建下载文件夹
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}
通过以上内容,您将能够轻松操作下载的文件。
虽然上面的答案很好,但对我来说下面的代码有效。
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
作为我测试的一部分,我想在浏览器加载 pdf 文件后立即自动从浏览器下载它。谁能指导我这是怎么回事 achieved.Following 是我 tried.I 尝试点击下载按钮的方式,但它对我不起作用。以下是在浏览器上显示的屏幕截图。
*** 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
我有一个非常简单的文件下载解决方法。它有以下规则:
在套件设置中创建下载文件夹
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}
通过以上内容,您将能够轻松操作下载的文件。
虽然上面的答案很好,但对我来说下面的代码有效。
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