在自动化测试过程中,我们会经常遇到附件上传,而附件上传主要分为两种:、,我们本章就两种不同类型的上传方式讲解:
(1)input型
针对这种我们的操作方式如下:
(2)非input型
使用SendKeys第三方库
安装方式:
使用AutoIT
:官网下载地址
图片1.png
AutoIt Windows Info 用于帮助我们识Windows控件信息。
Compile Script to.exe 用于将AutoIt生成 exe 执行文件。
Run Script 用于执行AutoIt脚本。
SciTE Script Editor 用于编写AutoIt脚本。
可以参考中文文档
1.首先打开AutoIt Windows Info 工具,鼠标点击Finder Tool(按住左键不松手),鼠标将变成一个小风扇形状的图标,移动到目标控件上;如图:
图片2.png
2.通过AutoIt Windows Info 获得以下信息。
窗口的title为“文件上传”,标题的Class为“#32770”。
文件名输入框的class 为“Edit”,Instance为“1” ,ClassnameNN为“Edit1”。
打开按钮的class 为“Button”,Instance为“1” ,所以ClassnameNN为“Button1”。
3.编写脚本(因为IE、Chrome、FireFox文件上传的左上角位置title不一致,所以我们坐下适配)
SciTE Script Editor应用程序
PS脚本来自lucky_zhang
打开autoit安装目录下的应用程序:Compile Script to .exe (x86)或者Compile Script to .exe (x64)
图片4.png