当前位置:网站首页>File upload and download of robot framework
File upload and download of robot framework
2022-04-23 16:36:00 【Sink the wine cup and fleeting time】
RobotFramework And File upload and download
In the course of the project , We often encounter file upload and download operations , Various ways can also be found online , This is about RobotFramework
In the framework of UI automation
File uploading and downloading in the process
Upload files
RobotFramework
frame Selenium2Library
There is one in the library choose file
keyword , It can upload files
grammar :
choose file Upload button element location File path
Here we still take the email upload file as an example . For operations on Web pages , Can pass selenium IDE( install ) Recording script , Save yourself time locating elements .
Here is the button for uploading files , It's actually bound to input
On the property
test.robot
*** Settings ***
Library Selenium2Library
Suite Setup Log in to Netease mailbox
Suite Teardown Close the browser
*** Keywords ***
Log in to Netease mailbox
open browser https://mail.163.com/ chrome
sleep 5
maximize browser window
# Switch to iframe
select frame xpath=//iframe[contains(@id,'iframe')]
# Enter... In the user name input box user name
sleep 2
input text xpath=//*[@name="email"] Your account number
sleep 2
# Enter... In the password input box password
input text xpath=//*[@name="password"] Your password
sleep 2
# Click the login button
click element xpath=//*[@id="dologin"]
sleep 5
Close the browser
close browser
*** Test Cases ***
Test upload file
click element xpath=//span[contains(.,' Write Letter ')]
sleep 5
choose file xpath=//input[@type='file'] F:/RFstudy/filepath/upload/1.jpg
sleep 10
File upload takes time , So set the waiting time as long as possible , Avoid file upload failure due to network reasons
File download
It's easy to download files , There is usually a download button on the page , Just click the download button
Chrome The browser can download files without pop-up boxes , Just set it in the browser ( It seems that by default, if you control the browser to download files through the driver file, there will be no pop-up box ) The file will be downloaded to by default C:\Users\Admin\Downloads
Under the table of contents
test.robot
*** Settings ***
Library Selenium2Library
Suite Setup Log in to Netease mailbox
Suite Teardown Close the browser
*** Keywords ***
Log in to Netease mailbox
open browser https://mail.163.com/ chrome
sleep 5
maximize browser window
# Switch to iframe
select frame xpath=//iframe[contains(@id,'iframe')]
# Enter... In the user name input box user name
sleep 2
input text xpath=//*[@name="email"] Your account number
sleep 2
# Enter... In the password input box password
input text xpath=//*[@name="password"] Your password
sleep 2
# Click the login button
click element xpath=//*[@id="dologin"]
sleep 5
Close the browser
close browser
*** Test Cases ***
Test Download File
click element xpath=//span[contains(.,' closed Letter ')]
sleep 2
click element xpath=//div[4]/div[2]/div/div[2]/span
sleep 2
click element xpath=//a[contains(text(),' See attachment ')]
sleep 2
click element xpath=//td/div/img
sleep 2
click element xpath=//a[contains(text(),' download ')]
sleep 10
If you need to specify to download to the corresponding directory , You need to open the browser to access the website , Load the corresponding configuration
You can modify the login keyword here , Every time I log in , Can pass in a parameter ( File download directory ); It can also be done without transmission , A download directory is given by default , Do not download files , The login function can also continue to be used
test.robot
*** Keywords ***
Log in to Netease mailbox and specify the file download directory
[Arguments] ${
File download directory }=${
Default download directory }
${
options} evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys,selenium.webdriver
${
prefs} create dictionary download.default_directory ${
File download directory } # Specify the directory to download the files
call method ${
options} add_experimental_option prefs ${
prefs}
create webdriver Chrome chrome_options=${
options}
open browser https://mail.163.com/ chrome
sleep 5
maximize browser window
# Switch to iframe
select frame xpath=//iframe[contains(@id,'iframe')]
# Enter... In the user name input box user name
sleep 2
input text xpath=//*[@name="email"] Your account number
sleep 2
# Enter... In the password input box password
input text xpath=//*[@name="password"] Your password
sleep 2
# Click the login button
click element xpath=//*[@id="dologin"]
sleep 5
版权声明
本文为[Sink the wine cup and fleeting time]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231402128805.html
边栏推荐
- How to upgrade openstack across versions
- Sail soft implements a radio button, which can uniformly set the selection status of other radio buttons
- MySQL personal learning summary
- Redis "8" implements distributed current limiting and delay queues
- G008-HWY-CC-ESTOR-04 华为 Dorado V6 存储仿真器配置
- ESP32_ Arduino
- Cloud migration practice in the financial industry Ping An financial cloud integrates hypermotion cloud migration solution to provide migration services for customers in the financial industry
- Change the icon size of PLSQL toolbar
- LVM与磁盘配额
- Homewbrew installation, common commands and installation path
猜你喜欢
JMeter setting environment variable supports direct startup by entering JMeter in any terminal directory
New project of OMNeT learning
Summary according to classification in sail software
深度学习100例 | 第41天-卷积神经网络(CNN):UrbanSound8K音频分类(语音识别)
Detailed explanation of file operation (2)
Gartner predicts that the scale of cloud migration will increase significantly; What are the advantages of cloud migration?
451. 根据字符出现频率排序
欣旺达:HEV和BEV超快充拳头产品大规模出货
TIA botu - basic operation
如何建立 TikTok用户信任并拉动粉丝增长
随机推荐
ES常用查询、排序、聚合语句
Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
The solution of not displaying a whole line when the total value needs to be set to 0 in sail software
LVM and disk quota
Database dbvisualizer Pro reported file error, resulting in data connection failure
Use if else to judge in sail software - use the title condition to judge
安装及管理程序
Differences between MySQL BTREE index and hash index
JSP learning 1
OMNeT学习之新建工程
Execution plan calculation for different time types
Vim使用Vundle安装代码补全插件(YouCompleteMe)
Server log analysis tool (identify, extract, merge, and count exception information)
Passing header request header information between services through feign
About JMeter startup flash back
昆腾全双工数字无线收发芯片KT1605/KT1606/KT1607/KT1608适用对讲机方案
阿里研发三面,面试官一套组合拳让我当场懵逼
Hyperbdr cloud disaster recovery v3 Version 2.1 release supports more cloud platforms and adds monitoring and alarm functions
Custom implementation of Baidu image recognition (instead of aipocr)