其他分享
首页 > 其他分享> > AUTOIT的使用

AUTOIT的使用

作者:互联网

 

其中:

AutoIt Windows Info   用于识别Windows控件信息

Compile Script to.exe  用于将AutoIt生成 exe 执行文件

Run Script    用于执行AutoIt脚本

SciTE Script Editor   用于编写AutoIt脚本

 


二、准备测试的html页面,代码如下,保存为uploadFile.html。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>upload_file</title>
</head>
<body>
  <div class="row-fluid">
    <div class="span6 well">
    <h3>upload_file</h3>
      <input type="file" name="file" /></br></br></br>
      <input type="text" disabled="disabled>
    </div>
  </div>
</body>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js"></script>
</html>

 

 

三、用AutoIt实现uploadFile.html上传文件弹出窗口的操作,生成.exe文件。

1、点击uploadFile.html页面的浏览按钮,弹出选择文件对话框

 

 

 

2、打开AutoIt Windows Info 工具,点击Finder Tool下小风扇形状图标,按住鼠标左键拖动到需要识别的控件上。

AutoIt Windows Info识别“文件名”输入框控件

 

 

 

AutoIt Windows Info识别“打开”按钮控件

 

 

 通过上面两个图AutoIt Windows Info中Control页面 获得以下信息。

窗口的title为“文件上传”,标题的Class为“#32770”。

文件名输入框的class 为“Edit”,Instance为“1” ,ClassnameNN为“Edit1”。

打开按钮的class 为“Button”,Instance为“1” ,ClassnameNN为“Button1”。

 

3、打开SciTE Script Editor编辑器,编写脚本。

SciTE Script Editor编辑器如下图:

 

代码如下:

;ControlFocus()方法用于识别Window窗口

ControlFocus("文件上传", "","Edit1")
 
 
; WinWait()设置10秒钟用于等待窗口的显示
  WinWait("[CLASS:#32770]","",10)
 
 
; ControlSetText()用于向“文件名”输入框内输入本地文件的路径,如果是在桌面第三个参数直接写文件名
 
  ControlSetText("文件上传", "", "Edit1", "代账客户批量导入模板 .xls")
 
  Sleep(1000)
 
; ControlClick()用于点击上传窗口中的“打开”按钮
 
  ControlClick("文件上传", "","Button1");


4、将脚本保存为uploadFile.au3,然后保持uploadFile.html的上传文件窗口处于打开状态,再通过通过Run Script 工具将uploadFile.au3打开运行

 

 

 

 

 

5、打开Compile Script to.exe工具,将ploadFile.au3生成为exe可执行文件:

 

 

 四、通过自动化测试脚本调用upfile.exe程序实现上传,Java代码如下:

import org.openqa.selenium.firefox.FirefoxDriver;
 
/*
 *作者:灵枢
 *时间:2017-2-14  下午7:45:35
 *描述:使用AutoIt上传文件
 **/
public class UploadFile {
    public static void main(String[] args) {
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("file:///C:/Users/Administrator/Desktop/uploadFile.html");
        //点击“浏览”
        driver.findElementByName("file").click();
        
        Runtime rn = Runtime.getRuntime();
        try {
            String str = "E://uploadFile.exe";
            rn.exec(str);
        } catch (Exception e) {
            System.out.println("Error to run the exe");
        }
    }
}

原文链接:https://blog.csdn.net/galen2016/java/article/details/55104927

 

标签:exe,uploadFile,Windows,Script,AutoIt,使用,AUTOIT,上传
来源: https://www.cnblogs.com/lee88888/p/12868643.html