IronPython应用之WinAPI(窗体捕获操作,AutoPyTest自动化测试)

(一)辅助工具

Python脚本编辑器:推荐CodeAssistor(AutoPyTest独立工具Plugs目录下)

Windows控件分析:类Spy++的改动版(AutoPyTest独立工具Plugs目录下)

(二)Python脚本例子

import clr, sys
sys.path.append("C:\\Program Files\\IronPython 2.7\\Lib")
import os
clr.AddReference('IronPythonTest')
clr.AddReference('System.Windows.Forms')
from IronPythonTest import *
from System.Windows.Forms import *
from time import sleep

#s_hwnd = ApiMethod.FindWindow(None, "IronPythonTest (正在运行) - Microsoft Visual Studio");
#s_hwnd = ApiMethod.GetProcessMainFormHandle("devenv");
#ApiMethod.ShowWindow(s_hwnd, ApiCode.SW_MAXIMIZE);
#ApiMethod.SetForegroundWindow(s_hwnd);
#ApiMethod.SendStringXY(s_hwnd, "你好", 531, 66);
#from System.Windows.Forms.SendKeys
#SendKeys.SendWait("~");


os.popen("C: && C:\\Windows\\System32\\calc.exe","r")
sleep(3.0);
#_mainWnd = ApiMethod.FindWindow(None, "计算器");
mainWnd = ApiMethod.GetProcessMainFormHandle("calc");
sleep(1.0);
ApiMethod.ShowWindow(mainWnd, ApiCode.SW_SHOWDEFAULT);
ApiMethod.SetForegroundWindow(mainWnd);
sleep(1.0);
#ApiMethod.SetWindowCurrent(mainWnd);
#hwnd_button = ApiMethod.FindWindowEx(mainWnd, new IntPtr(0), null, "OK");
hwnd_button = ApiMethod.GetChildByID(mainWnd, 121);
ApiMethod.SendString(mainWnd,"1+2+4");
sleep(1.0);
ApiMethod.SendString(mainWnd, "*2");
sleep(1.0);
ApiMethod.SendMessage(hwnd_button,ApiCode.WM_CLICK , mainWnd, "0");
sleep(1.0);
SendKeys.SendWait("%{2}");
sleep(1.0);
SendKeys.SendWait("^{h}");
sleep(1.0);
flag=ApiMethod.ClickPosXY(mainWnd, 35, 38);
sleep(1.0);
flag=ApiMethod.ClickPosXY(mainWnd, 35, 38);
sleep(1.0);
SendKeys.SendWait("{F1}");

(三)界面和效果

AutoPyTest获取:

资源下载:http://download.csdn.net/detail/w565911788/4323928 (自解压绿色安装包)

需安装环境:dotNetFx40_Full_x86_x64.exe; IronPython-2.7.2.1.msi; (或以上)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值