python automation_Robot Framework + Pywinauto 框架實現Windows GUI Automation

作者: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

e123ff3e617b10bea5e05c081dd40095.png

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

f0ed6974fb0c448bb301f82b8bf032b6.png

2. Add self defined Library to robot framework

2.1 Method#1: Add Library in Test Suite

d124c0a112fb7c32e980361e6090802c.png

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

6ec8f22d49fd860cc01a254f3f8475ef.png

Launch RIDE

1. Add New Project:

2. Add New Test Suite:

e42c2d08e020616f3584ece156835ea1.png

3. Add New Test Case:

78ad1cd134d5544d278dd9bf57160c18.png

4. Write test case:

79b841a0150b2cba62e36079cd5369d5.png

Run the Scripts via RIDE

08ec8b57acd624ed021f9ac6cb32bbbb.png

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

6a747d1e8bdbc600fd86eb1379445f9e.png

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

db90ec4b51d134bfebd627f937dea146.png

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

718868146e4cd21fba6ec8468c1d5d7a.png

8aa69ab4925afb49b38e683e48d0cc2d.png

93ea3fd4b1dd5dac3d6a969e54d7385d.png

WebSite:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值