当前位置:网站首页>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
边栏推荐
- 七朋元视界可信元宇宙社交体系满足多元化的消费以及社交需求
- Cartoon: what are IAAs, PAAS, SaaS?
- JSP learning 3
- 建站常用软件PhpStudy V8.1图文安装教程(Windows版)超详细
- What does cloud disaster tolerance mean? What is the difference between cloud disaster tolerance and traditional disaster tolerance?
- Loading order of logback configuration file
- Interview question 17.10 Main elements
- 文件操作详解(2)
- 面试题 17.10. 主要元素
- How to quickly batch create text documents?
猜你喜欢
力扣-198.打家劫舍
如何建立 TikTok用户信任并拉动粉丝增长
Xinwangda: HEV and Bev super fast charging fist products are shipped on a large scale
Sort by character occurrence frequency 451
MySql主从复制
Nacos detailed explanation, something
英语 | Day15、16 x 句句真研每日一句(从句断开、修饰)
Sail soft calls the method of dynamic parameter transfer and sets parameters in the title
Government cloud migration practice: Beiming digital division used hypermotion cloud migration products to implement the cloud migration project for a government unit, and completed the migration of n
Day (6) of picking up matlab
随机推荐
Meaning and usage of volatile
05 Lua 控制结构
各大框架都在使用的Unsafe类,到底有多神奇?
Hypermotion cloud migration helped China Unicom. Qingyun completed the cloud project of a central enterprise and accelerated the cloud process of the group's core business system
logback的配置文件加载顺序
The system research problem that has plagued for many years has automatic collection tools, which are open source and free
Sort by character occurrence frequency 451
Gartner predicts that the scale of cloud migration will increase significantly; What are the advantages of cloud migration?
Install MySQL on MAC
Server log analysis tool (identify, extract, merge, and count exception information)
Hypermotion cloud migration completes Alibaba cloud proprietary cloud product ecological integration certification
Government cloud migration practice: Beiming digital division used hypermotion cloud migration products to implement the cloud migration project for a government unit, and completed the migration of n
OMNeT学习之新建工程
Start Oracle service on Linux
Best practice of cloud migration in education industry: Haiyun Jiexun uses hypermotion cloud migration products to implement progressive migration for a university in Beijing, with a success rate of 1
Day (2) of picking up matlab
Download and install mongodb
如何建立 TikTok用户信任并拉动粉丝增长
Take according to the actual situation, classify and summarize once every three levels, and see the figure to know the demand
最詳細的背包問題!!!