首页 > 代码库 > jmeter结合autoit操作windows程序

jmeter结合autoit操作windows程序

需求:

模拟操作下图软件的控件,如拨号和挂机。

技术分享

 

1. 下载安装好autoit后,打开finder tool,使用查找工具定位到要模拟操作的控件上,如图:

技术分享

2.在finder tool中的control选项卡,可以看到该控件的信息。其它控件做类似操作

技术分享

3.打开autoit的script editor,编写模拟操作控件的脚本

Dim $dialogTitle = "MicroSIP"

WinActivate($dialogTitle)
WinWaitActive($dialogTitle)


;1
ControlFocus("MicroSIP", "","[Class:Button;Instance:7]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:7]")

;0
ControlFocus("MicroSIP", "","[Class:Button;Instance:16]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:16]")
ControlFocus("MicroSIP", "","[Class:Button;Instance:16]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:16]")
;8
ControlFocus("MicroSIP", "","[Class:Button;Instance:14]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:14]")
;6
ControlFocus("MicroSIP", "","[Class:Button;Instance:12]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:12]")
;2
ControlFocus("MicroSIP", "","[Class:Button;Instance:8]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:8]")
ControlFocus("MicroSIP", "","[Class:Button;Instance:8]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:8]")

ControlFocus("MicroSIP", "","[Class:Button;Instance:1]")
Sleep(1000)
ControlClick("MicroSIP", "","[Class:Button;Instance:1]")

  

4.保存为au3文件,点击scrit的tools->go。测试运行,通过后,打开autoit的script to exe工具,将步骤3的au3文件转为换exe文件

技术分享

 

5.打开jmeter,一次添加计划、线程组->BeanShell Sampler,在beanshell中添加调用exe的java代码

Runtime rn = Runtime.getRuntime();
Process p = null;
try {          
	p = rn.exec("\"C:/callout1008622.exe\"");
} catch (Exception e) {
	System.out.println("Error exec!");
  }

  

6.保存后,启动jmeter,运行通过

jmeter结合autoit操作windows程序