RobotFramework+AutoItLibrary文件上传

RobotFramework+AutoItLibrary文件上传

安装AutoLibrary

1、进入CMD命令窗口

1
pip list # 查看列表中是否包含了pywin32如果有则跳过步骤 2

2、没有pywin32的情况下进入python安装文件执行CMD命令

1
pip install pywin32   # 安装pywin32

3、下载AutoItLibrary(http://code.google.com/p/robotframework-autoitlibrary/)
下载完成之后解压
4、以管理员身份运行CMD命令窗口、切换路径到之前下载解压AutoItLibrary文件下
输入命令:

1
python setup.py install

connect

显示上面的图片未提示报错信息则安装AutoItLibrary成功
5、将AutoLibrary导入到RobotFramework中

connect

未显示红色字体则AutoItLibrary导入成功

6、安装好了AutoItLibrary打开它会出现如图的一个控件:

connect


使用AutoItLibrary

1、在文件解压包中找到AutoInfo.exe、双击运行

connect
2、你会在Finder Tool位置发信啊有个十字星,可以用鼠标拖动到你需要识别的对象上。如图:

connect

3、获取文件名和确定按钮对象的位置如图:

connect


使用结合Selenium2Library处理上传

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
*** Settings ***
Library Selenium2Library
Library AutoItLibrary

*** Variables ***
${ip} http://ehrtest.source3g.com/auth/#/login?26f06007489445319dad4265836b66be # 登录EHR系统的IP地址
${user} zhangyue # 登录EHR的用户名
${pwd} 888888 # 登录EHR系统的密码

*** Test Cases ***
fileup
Open Browser ${ip} firefox
Input Text xpath=//*[@id="app"]/div/div[2]/form/div[1]/div/div/input ${user}
Input Text xpath=//*[@id="app"]/div/div[2]/form/div[2]/div/div/input ${pwd}
Click Button xpath=.//*[@id='app']/div/div[2]/form/div[3]/button
Wait Until Page Contains Element xpath=//div[@id='app']/div/div[2]/ul/li[5]/div/i[2] 20 ERROR
Click Element xpath=//div[@id='app']/div/div[2]/ul/li[5]/div/i[2]
Wait Until Page Contains Element xpath=//div[@id='app']/div/div[2]/ul/li[5]/ul/li[3] 20 ERROR
Click Element xpath=//div[@id='app']/div/div[2]/ul/li[5]/ul/li[3]
Wait Until Page Contains Element xpath=//div[@id='app']/div/div[3]/div/div[2]/div/div/div 20 ERROR
Click Element xpath=//div[@id='app']/div/div[3]/div/div[2]/div/div/div
Control Send 文件上传 ${EMPTY} [CLASS:Edit; INSTANCE:1] 111.xlsx
Sleep 2
Control Click 文件上传 ${EMPTY} Button1
Sleep 3
Page Should Not Contain Element css=.el-message__content 文件上传失败 INFO

connect

代码思路:

1、选通过Selenium2Library打开浏览器、并且获取到上传文件控件的xpath路径。(第一行到第十行)

2、通过 AutoItLibrary获取window窗口中的对象的位置(第十一行和第十三行)主要是获取文件选择对话框中的输入文件名的输入框和“确定”按钮

3、获取windows对象属性(Summary标签下的(ClassNN或者Advanced(Class)))后面的值
connect

热评文章