Robot Framework + Pywinauto 框架实现Windows GUI Automation

2018/05/03 21:27
阅读数 342

作者:Daly 出处:http://www.cnblogs.com/daly 欢迎转载,也请保留这段声明。谢谢! 

最近刚给Windows GUI automation项目介的实现框架,总结记录一下, 供以后查看。

Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach.

Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases.
Robot Framework itself is open source software and most of the libraries and tools in the ecosystem are also open source.
With a lot of standard and external libraries.

Pywinauto is a GUI automation library written in pure Python and well developed for Windows GUI. At its simplest it allows you to send mouse and keyboard actions to dialogs and controls on both Windows and Linux, while more complex text-based actions are supported on Windows only so far (Linux AT-SPI support is under development).

This big release introduces MS UI Automation (UIA) support (WinForms, WPF, Qt, browsers, Store apps and more).
Modules keyboard and mouse can be used out of any window context now. And they work on Linux as well! Multi-backend architecture allows to add new platforms support. 

Robot Framework + Pywinauto

1. Encapsulate the pywinauto codes(functions) to self defined libraries for Robot Framework

 

2. Add self defined Library to robot framework
2.1 Method#1: Add Library in Test Suite

2.2 Method#2: Import the Library directly in the Test Case

 

Launch RIDE

1. Add New Project:

2. Add New Test Suite:

 

3. Add New Test Case:

 

4. Write test case:

Run the Scripts via RIDE

Click Log/Report button to view the Log/Report in browser:

ENV Preparation
1. Install Python
Install python 2. x or python 3.x (https://wiki.python.org/moin/Python2orPython3)
Notes:
1.1 Add python.exe to the PATH Environmental Variable(Can check this via installation)
1.2 RIDE does not support Python3
1.3 pip is already installed if you are using Python 2 >=2.7.9 or Python 3 >=3.4
2. Install wxPython (For RIDE UI)
Method#1: pip install wxPython
Method#2: cd to the source code and run python setup.py install in command line
Method#3: install wxPython-xxx.exe(You need to install wxPython 2.8.12.1 with unicode support to run RIDE)
3. Install Robot Framework
Method#1: pip install robotframework
Method#2: cd to the source code and run python setup.py install in command line
4. Install RIDE
Method#1: pip install robotframework-ride
Method#2: cd to the source code and run python setup.py install in command line
5. Install pywinatuo
Method#1: pip install pywinauto
Method#2: cd to the source code and run python setup.py install in command line
Notes: If pip can work, can install item#2 to item#5 together via one command: pip install -r requirements.txt

Add PYTHONPATH in Environmental Variable

 

Notes:
1. If the self defined library does not in the PATH, you can add related directory to the PYTHONPATH

IDE
For Python:
Eclipse (Use Python plugin)
PyCharm

For RobotFramework:
RIDE (A lightweight and intuitive editor for Robot Framework test data.)
Start RIDE: cd to x:\Python27\Scripts\ and execute python ride.py in command line
Eclipse (Use RobotFramework plugin)

Tools
GUI Inspect Tool

1. Swapy.exe

This tool based on
Pywinauto 0.5.4

2. Inspect.exe

3. AccExplorer.exe

RIDE Settings

 

WebSite:

http://robotframework.org/
https://pypi.org/project/robotframework/
https://github.com/robotframework/robotframework

http://pywinauto.github.io/
https://pywinauto.readthedocs.io/en/latest/
https://github.com/pywinauto/pywinauto/releases

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部