当前位置:网站首页>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
- 力扣-746.使用最小花费爬楼梯
- Detailed explanation of file operation (2)
- ESP32_ Arduino
- Nacos 详解,有点东西
- Detailed explanation of gzip and gunzip decompression parameters
- On the security of key passing and digital signature
- OMNeT学习之新建工程
- Questions about disaster recovery? Click here
- MySql主从复制
猜你喜欢
You need to know about cloud disaster recovery
Install MySQL on MAC
OMNeT学习之新建工程
Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
What is the experience of using prophet, an open source research tool?
Use itextpdf to intercept the page to page of PDF document and divide it into pieces
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
Day (5) of picking up matlab
力扣-746.使用最小花费爬楼梯
安装Redis并部署Redis高可用集群
随机推荐
无线鹅颈麦主播麦手持麦无线麦克风方案应当如何选择
RAID磁盘阵列与RAID5的创建
Cloudy data flow? Disaster recovery on cloud? Last value content sharing years ago
关于 background-image 渐变gradient()那些事!
最詳細的背包問題!!!
Start Oracle service on Linux
The font of the soft cell changes color
Hyperbdr cloud disaster recovery v3 Release of version 3.0 | upgrade of disaster recovery function and optimization of resource group management function
Nacos detailed explanation, something
Force buckle-746 Climb stairs with minimum cost
伪分布安装spark
TIA botu - basic operation
Custom implementation of Baidu image recognition (instead of aipocr)
安装Redis并部署Redis高可用集群
Day (5) of picking up matlab
Six scenarios of cloud migration
homwbrew安装、常用命令以及安装路径
On the value, breaking and harvest of NFT project
Download and install mongodb
Creation of RAID disk array and RAID5