python自动化测试windows gui

http://sourceforge.net/projects/pywinauto/files/pywinauto/

http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266

https://pypi.python.org/pypi/SendKeys/

http://files.cnblogs.com/files/zhang-pengcheng/SendKeys-0.3.zip

Python高级编程(随书代码)

http://files.cnblogs.com/files/zhang-pengcheng/Python%E9%AB%98%E7%BA%A7%E7%BC%96%E7%A8%8B%EF%BC%88%E9%9A%8F%E4%B9%A6%E4%BB%A3%E7%A0%81%EF%BC%89.zip

自动化脚本

http://blog.csdn.net/xinpo66/article/details/9034473

http://blog.csdn.net/xinpo66/article/details/9034507

http://nullege.com/codes/search/pywinauto.application.Application.Notepad.Edit.TypeKeys

G:2.soft$$pythonpypywinauto-0.4.0pywinauto-0.4.0docscontrols_overview.html

# modifier keys
MODIFIERS = {
    '+': VK_SHIFT,
    '^': VK_CONTROL,
    '%': VK_MENU,
}

# 'codes' recognized as {CODE( repeat)?}
CODES = {
    'BACK':     8,
    'BACKSPACE':8,
    'BKSP':     8,
    'BREAK':    3,
    'BS':       8,
    'CAP':      20,
    'CAPSLOCK': 20,
    'DEL':      46,
    'DELETE':   46,
    'DOWN':     40,
    'END':      35,
    'ENTER':    13,
    'ESC':      27,
    'F1':       112,
    'F2':       113,
    'F3':       114,
    'F4':       115,
    'F5':       116,
    'F6':       117,
    'F7':       118,
    'F8':       119,
    'F9':       120,
    'F10':      121,
    'F11':      122,
    'F12':      123,
    'F13':      124,
    'F14':      125,
    'F15':      126,
    'F16':      127,
    'F17':      128,
    'F18':      129,
    'F19':      130,
    'F20':      131,
    'F21':      132,
    'F22':      133,
    'F23':      134,
    'F24':      135,
    'HELP':     47,
    'HOME':     36,
    'INS':      45,
    'INSERT':   45,
    'LEFT':     37,
    'LWIN':     91,
    'NUMLOCK':  144,
    'PGDN':     34,
    'PGUP':     33,
    'PRTSC':    44,
    'RIGHT':    39,
    'RMENU':    165,
    'RWIN':     92,
    'SCROLLLOCK':145,
    'SPACE':     32,
    'TAB':       9,
    'UP':        38,

    'VK_ACCEPT': 30,
    'VK_ADD':    107,
    'VK_APPS':    93,
    'VK_ATTN':    246,
    'VK_BACK':    8,
    'VK_CANCEL':  3,
    'VK_CAPITAL': 20,
    'VK_CLEAR':   12,
    'VK_CONTROL': 17,
    'VK_CONVERT': 28,
    'VK_CRSEL':   247,
    'VK_DECIMAL': 110,
    'VK_DELETE':  46,
    'VK_DIVIDE':  111,
    'VK_DOWN':    40,
    'VK_END':     35,
    'VK_EREOF':   249,
    'VK_ESCAPE':  27,
    'VK_EXECUTE': 43,
    'VK_EXSEL':   248,
    'VK_F1':      112,
    'VK_F2':      113,
    'VK_F3':      114,
    'VK_F4':      115,
    'VK_F5':      116,
    'VK_F6':      117,
    'VK_F7':      118,
    'VK_F8':      119,
    'VK_F9':      120,
    'VK_F10':     121,
    'VK_F11':     122,
    'VK_F12':     123,
    'VK_F13':     124,
    'VK_F14':     125,
    'VK_F15':     126,
    'VK_F16':     127,
    'VK_F17':     128,
    'VK_F18':     129,
    'VK_F19':     130,
    'VK_F20':     131,
    'VK_F21':     132,
    'VK_F22':     133,
    'VK_F23':     134,
    'VK_F24':     135,
    'VK_FINAL':   24,
    'VK_HANGEUL':  21,
    'VK_HANGUL':   21,
    'VK_HANJA':    25,
    'VK_HELP':     47,
    'VK_HOME':     36,
    'VK_INSERT':   45,
    'VK_JUNJA':    23,
    'VK_KANA':     21,
    'VK_KANJI':    25,
    'VK_LBUTTON':   1,
    'VK_LCONTROL':162,
    'VK_LEFT':     37,
    'VK_LMENU':   164,
    'VK_LSHIFT':  160,
    'VK_LWIN':     91,
    'VK_MBUTTON':    4,
    'VK_MENU':        18,
    'VK_MODECHANGE':  31,
    'VK_MULTIPLY':   106,
    'VK_NEXT':        34,
    'VK_NONAME':     252,
    'VK_NONCONVERT':  29,
    'VK_NUMLOCK':    144,
    'VK_NUMPAD0':     96,
    'VK_NUMPAD1':     97,
    'VK_NUMPAD2':     98,
    'VK_NUMPAD3':     99,
    'VK_NUMPAD4':    100,
    'VK_NUMPAD5':    101,
    'VK_NUMPAD6':    102,
    'VK_NUMPAD7':    103,
    'VK_NUMPAD8':    104,
    'VK_NUMPAD9':    105,
    'VK_OEM_CLEAR':  254,
    'VK_PA1':        253,
    'VK_PAUSE':       19,
    'VK_PLAY':       250,
    'VK_PRINT':       42,
    'VK_PRIOR':       33,
    'VK_PROCESSKEY': 229,
    'VK_RBUTTON':      2,
    'VK_RCONTROL':   163,
    'VK_RETURN':      13,
    'VK_RIGHT':       39,
    'VK_RMENU':      165,
    'VK_RSHIFT':     161,
    'VK_RWIN':        92,
    'VK_SCROLL':     145,
    'VK_SELECT':      41,
    'VK_SEPARATOR':  108,
    'VK_SHIFT':       16,
    'VK_SNAPSHOT':    44,
    'VK_SPACE':       32,
    'VK_SUBTRACT':   109,
    'VK_TAB':          9,
    'VK_UP':          38,
    'ZOOM':          251,
}

charmap

==============================Control Identifiers:
CharGridWClass - ''   (L802, T101, R1285, B434)
    'CharGridWClass' '字体(&F):CharGridWClass'
Static - '复制字符(&A):'   (L781, T455, R919, B474)
    'Static' 'Static0' 'Static1' '复制字符(&A):' '复制字符(&A):Static'
RICHEDIT50W - ''   (L927, T449, R1120, B483)
    'RICHEDIT50W' '复制字符(&A):RICHEDIT50W'
Button - '选择(&S)'   (L1126, T449, R1214, B479)
    'Button' 'Button0' 'Button1' '选择(&S)' '选择(&S)Button'
Button - '复制(&C)'   (L1221, T449, R1309, B479)
    'Button2' '复制(&C)' '复制(&C)Button'
Button - '高级查看(&V)'   (L781, T485, R893, B511)
    'CheckBox' '高级查看(&V)' '高级查看(&V)CheckBox'
Static - '字符集(&T):'   (L781, T530, R926, B549)
    'Static2' '字符集(&T):' '字符集(&T):Static'
ComboBox - 'Windows: 简体中文'   (L927, T523, R1163, B548)
    'ComboBox' 'ComboBox0' 'ComboBox1' '字符集(&T):ComboBox'
Static - '转到 Unicode(&U):'   (L1168, T532, R1256, B570)
    'Static3' '转到 Unicode(&U):' '转到 Unicode(&U):Static'
Edit - ''   (L1263, T523, R1307, B553)
    'Edit' 'Edit0' 'Edit1' '转到 Unicode(&U):Edit'
Static - '分组依据(&G):'   (L781, T568, R926, B587)
    'Static4' '分组依据(&G):' '分组依据(&G):Static'
ComboBox - '全部'   (L927, T561, R1162, B586)
    'ComboBox2' '分组依据(&G):ComboBox'
Static - '搜索(&E):'   (L781, T608, R926, B627)
    'Static5' '搜索(&E):' '搜索(&E):Static'
Edit - ''   (L927, T600, R1165, B630)
    'Edit2' '搜索(&E):Edit'
Button - '搜索(&R)'   (L1182, T600, R1270, B630)
    'Button3' '搜索(&R)' '搜索(&R)Button'
Static - '字体(&F):'   (L781, T64, R842, B83)
    'Static6' '字体(&F):' '字体(&F):Static'
ComboBox - 'TOPhonetic'   (L843, T58, R1218, B81)
    'ComboBox3' '字体(&F):ComboBox'
Button - '帮助(&H)'   (L1224, T58, R1312, B88)
    'Button4' '帮助(&H)' '帮助(&H)Button'

==============================Control Identifiers:
CharGridWClass - ''   (L802, T101, R1285, B434)
    'CharGridWClass' '字体(&F):CharGridWClass'
Static - '复制字符(&A):'   (L781, T455, R919, B474)
    'Static' 'Static0' 'Static1' '复制字符(&A):' '复制字符(&A):Static'
RICHEDIT50W - ''   (L927, T449, R1120, B483)
    'RICHEDIT50W' '复制字符(&A):RICHEDIT50W'
Button - '选择(&S)'   (L1126, T449, R1214, B479)
    'Button' 'Button0' 'Button1' '选择(&S)' '选择(&S)Button'
Button - '复制(&C)'   (L1221, T449, R1309, B479)
    'Button2' '复制(&C)' '复制(&C)Button'
Button - '高级查看(&V)'   (L781, T485, R893, B511)
    'CheckBox' '高级查看(&V)' '高级查看(&V)CheckBox'
Static - '字符集(&T):'   (L781, T530, R926, B549)
    'Static2' '字符集(&T):' '字符集(&T):Static'
ComboBox - 'Windows: 简体中文'   (L927, T523, R1163, B548)
    'ComboBox' 'ComboBox0' 'ComboBox1' '字符集(&T):ComboBox'
Static - '转到 Unicode(&U):'   (L1168, T532, R1256, B570)
    'Static3' '转到 Unicode(&U):' '转到 Unicode(&U):Static'
Edit - ''   (L1263, T523, R1307, B553)
    'Edit' 'Edit0' 'Edit1' '转到 Unicode(&U):Edit'
Static - '分组依据(&G):'   (L781, T568, R926, B587)
    'Static4' '分组依据(&G):' '分组依据(&G):Static'
ComboBox - '全部'   (L927, T561, R1162, B586)
    'ComboBox2' '分组依据(&G):ComboBox'
Static - '搜索(&E):'   (L781, T608, R926, B627)
    'Static5' '搜索(&E):' '搜索(&E):Static'
Edit - ''   (L927, T600, R1165, B630)
    'Edit2' '搜索(&E):Edit'
Button - '搜索(&R)'   (L1182, T600, R1270, B630)
    'Button3' '搜索(&R)' '搜索(&R)Button'
Static - '字体(&F):'   (L781, T64, R842, B83)
    'Static6' '字体(&F):' '字体(&F):Static'
ComboBox - 'TOPhonetic'   (L843, T58, R1218, B81)
    'ComboBox3' '字体(&F):ComboBox'
Button - '帮助(&H)'   (L1224, T58, R1312, B88)
    'Button4' '帮助(&H)' '帮助(&H)Button'

## pytesser是一个用于图片文本识别的python模块,即从文本的截图中还原出文本信息

>>> from pytesser import *
>>> image = Image.open('fnord.tif')  # Open image object using PIL
>>> print image_to_string(image)     # Run tesseract.exe on image
fnord
>>> print image_file_to_string('fnord.tif')
fnord

try:
    import Image
except ImportError:
    from PIL import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))

### py-ocr

import Image
import sys
from pyocr import pyocr
tools = pyocr.get_available_tools()[:]
if len(tools) == 0:
    print("No OCR tool found")
    sys.exit(1)
print("Using '%s'" % (tools[0].get_name()))
tools[0].image_to_string(Image.open('test.png'), lang='fra',
                         builder=TextBuilder())

### py-ocr

from PIL import Image
import sys

import pyocr
import pyocr.builders

tools = pyocr.get_available_tools()
if len(tools) == 0:
    print("No OCR tool found")
    sys.exit(1)
tool = tools[0]
print("Will use tool '%s'" % (tool.get_name()))
# Ex: Will use tool 'tesseract'

langs = tool.get_available_languages()
print("Available languages: %s" % ", ".join(langs))
lang = langs[0]
print("Will use lang '%s'" % (lang))
# Ex: Will use lang 'fra'

txt = tool.image_to_string(Image.open('test.png'),
                           lang=lang,
                           builder=pyocr.builders.TextBuilder())
word_boxes = tool.image_to_string(Image.open('test.png'),
                                  lang=lang,
                                  builder=pyocr.builders.WordBoxBuilder())
line_and_word_boxes = tool.image_to_string(
        Image.open('test.png'), lang=lang,
        builder=pyocr.builders.LineBoxBuilder())

# Digits - Only Tesseract
digits = tool.image_to_string(Image.open('test-digits.png'),
                              lang=lang,
                              builder=pyocr.tesseract.DigitBuilder())

PyTesser 官方下载地址:http://code.google.com/p/pytesser/downloads/list

PIL库资源地址: http://www.pythonware.com/products/pil/

http://www.oschina.net/p/pyocr

Prerequisites:

  • Python-tesseract requires python 2.5 or later or python 3.
  • You will need the Python Imaging Library (PIL). Under Debian/Ubuntu, this is the package "python-imaging" or "python3-imaging" for python3.
  • Install google tesseract-ocr from http://code.google.com/p/tesseract-ocr/ . You must be able to invoke the tesseract command as "tesseract". If this isn't the case, for example because tesseract isn't in your PATH, you will have to change the "tesseract_cmd" variable at the top of 'tesseract.py'. Under Debian/Ubuntu you can use the package "tesseract-ocr".

## SourceForge、GitHub、Bitbucket、CodePlex

## SyntaxHighlighter

version 3.0.9 (Mon, 14 Jul 2014 13:04:28 GMT)

http://alexgorbatchev.com/SyntaxHighlighter

JavaScript code syntax highlighter.

Copyright 2004-2013 Alex Gorbatchev.

## 使用pyExcelerator来读写 Excel文件(详细)

### 写入

wb = Workbook()
ws = wb.add_sheet('result')
ws.write(0,0,“hello”)
wb.save('result.xls')

### 读

from pyExcelerator import *
sheets = parse_xls('d:/a.xls')

# eclipse字体设置

在Eclipse环境建立新的workspace目录时,workspace目录下会自动生成.metadata目录,其中保存Eclipse关于这个工作区的相关配置,历史记录等等数据

只好先修改配置文件:

工作区/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs 文件

org.eclipse.jface.textfont=1|Courier New|12.0|0|WINDOWS|1|-16|0|0|0|400|0|0|0|0|3|2|1|49|Courier New;改为

org.eclipse.jface.textfont=1|Courier New|14.0|0|WINDOWS|1|-16|0|0|0|400|0|0|0|0|3|2|1|49|Courier New;把字号由12改为14号

需要重启eclipse才生效

# eclim

Eclipse Luna SR2 (4.4.2) Release for Windows
E:Vimvimfiles
G:2-greenToolseclipse_4.4.2

# 请问如何查询COM接口里面的成员(属性,方法等等)

GetIDsOfNames.
OLE View

## Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTWord.Application]
@="Microsoft Word Application"

[HKEY_CLASSES_ROOTWord.ApplicationCLSID]
@="{000209FF-0000-0000-C000-000000000046}"

[HKEY_CLASSES_ROOTWord.ApplicationCurVer]
@="Word.Application.12"

#@ 如何在ole view中看到Word.Application的信息, 这个节点在哪里?

## Error Messages for Windows

http://www.gregorybraun.com/MSWinErr.html

## CTRL+D ECLIPSE

zen_actions.match_pair_outward - Nullege Python Samples

## COM三大接口:IUnknown、IClassFactory、IDispatch。

http://www.cnblogs.com/weiqubo/archive/2011/03/18/1988033.html

## C++调Python示例

http://www.cnblogs.com/Hisin/archive/2012/02/27/2370590.html

## pycom32

### PyObject(Common Object Structures)

All object types are extensions of this type. This is a type which contains the information Python needs to treat a pointer to an object as an object. In a normal “release” build, it contains only the object’s reference count and a pointer to the corresponding type object. It corresponds to the fields defined by the expansion of the PyObject_HEAD macro.

### PyIBase

class PYCOM_EXPORT PyIBase :
        public PyObject
{
public:
    // virtuals for Python support
    virtual PyObject *getattr(char *name);
    virtual int setattr(char *name, PyObject *v);
    virtual PyObject *repr();
    virtual int compare(PyObject *other) {
        if (this == other)
            return 0;
        if (this < other)
            return -1;
        return 1;
        }
    // These iter are a little special, in that returning NULL means
    // use the implementation in the type
    virtual PyObject *iter() {return NULL;}
    virtual PyObject *iternext() {return NULL;}
protected:
    PyIBase();
    virtual ~PyIBase();

public:
    static BOOL is_object(PyObject *, PyComTypeObject *which);
    BOOL is_object(PyComTypeObject *which);
    static void dealloc(PyObject *ob);
    static PyObject *repr(PyObject *ob);
    static PyObject *getattro(PyObject *self, PyObject *name);
    static int setattro(PyObject *op, PyObject *obname, PyObject *v);
    static int cmp(PyObject *ob1, PyObject *ob2);
    static PyObject *richcmp(PyObject *ob1, PyObject *ob2, int op);

};

### PyIUnknown

class PYCOM_EXPORT PyIUnknown : public PyIBase
{
public:
    MAKE_PYCOM_CTOR(PyIUnknown);
    virtual PyObject *repr();
    virtual int compare(PyObject *other);

    static IUnknown *GetI(PyObject *self);
    IUnknown *m_obj;
    static char *szErrMsgObjectReleased;
    static void SafeRelease(PyIUnknown *ob);
    static PyComTypeObject type;

    // The Python methods
    static PyObject *QueryInterface(PyObject *self, PyObject *args);
    static PyObject *SafeRelease(PyObject *self, PyObject *args);

protected:
    PyIUnknown(IUnknown *punk);
    ~PyIUnknown();
}

### PyIDispatch

class PYCOM_EXPORT PyIDispatch : public PyIUnknown
{
public:
    MAKE_PYCOM_CTOR(PyIDispatch);
    static IDispatch *GetI(PyObject *self);
    static PyComTypeObject type;

    // The Python methods
    static PyObject *Invoke(PyObject *self, PyObject *args);
    static PyObject *InvokeTypes(PyObject *self, PyObject *args);
    static PyObject *GetIDsOfNames(PyObject *self, PyObject *args);
    static PyObject *GetTypeInfo(PyObject *self, PyObject *args);
    static PyObject *GetTypeInfoCount(PyObject *self, PyObject *args);
protected:
    PyIDispatch(IUnknown *pdisp);
    ~PyIDispatch();
};

##

转自: http://blog.csdn.net/ccbird88/article/details/6193769

from win32com.client import Dispatch, constants
from win32com.client.gencache import EnsureDispatch
EnsureDispatch('Word.Application') #makepy 导入Word类库,否则constants无法使用
msword = Dispatch('Word.Application')
msword.Visible = True #是否可见
msword.DisplayAlerts = 0
doc = msword.Documents.Open(FileName = strDir + r'tbbts01e01.docx') #打开已有文件
newdoc = msword.Documents.Add() #添加新文件
newdoc.SaveAs(‘new.docx') #另存为

###

在使用win32com 之前,需要导入指定的类库(Makepy), 方法:

There are a couple of different ways to run makepy.

Start Pythonwin, and from the menu select Tools->Com Makepy Utility. You should see a list

of registered typelibs. Select "Microsoft Word x.y Object Library" and hit Ok.

This can also be done programatically by initiating Word with

win32com.client.gencache.EnsureDispatch('Word.Application')

## 转自http://hao.jobbole.com/python-docx/

from docx import Document

from docx.shared import Inches

document = Document()

document.add_heading('Document Title', 0)

p = document.add_paragraph('A plain paragraph having some ')

p.add_run('bold').bold = True

p.add_run(' and some ')

p.add_run('italic.').italic = True

document.add_heading('Heading, level 1', level=1)

document.add_paragraph('Intense quote', style='IntenseQuote')

document.add_paragraph(

'first item in unordered list', style='ListBullet'

)

document.add_paragraph(

'first item in ordered list', style='ListNumber'

)

document.add_picture('monty-truth.png', width=Inches(1.25))

table = document.add_table(rows=1, cols=3)

hdr_cells = table.rows[0].cells

hdr_cells[0].text = 'Qty'

hdr_cells[1].text = 'Id'

hdr_cells[2].text = 'Desc'

for item in recordset:

row_cells = table.add_row().cells

row_cells[0].text = str(item.qty)

row_cells[1].text = str(item.id)

row_cells[2].text = item.desc

document.add_page_break()

document.save('demo.docx')

老github主页:https://github.com/mikemaccana/python-docx
新github主页:https://github.com/python-openxml/python-docx

## eclipse svn
转自: http://blog.csdn.net/vebasan/article/details/6186344

一、给Eclipse安装SVN,最常见的有两种方式:手动方式和使用安装向导方式。具体步骤如下:

方式一:手动安装

1、从官网下载site-1.6.9.zip文件,网址是:subclipse.tigris.org
2、从中解压出features与plugins文件夹,复制到E:/MyEclipse/myPlugin/svn里面,其它的*.xml文件不要。
3、在E:/MyEclipse/MyEclipse X.X/dropins下新建文件svn.link,内容是:path=E://MyEclipse//myPlugin//svn 保存。
4、删除E:/MyEclipse/MyEclipse X.X/configuration/org.eclipse.update文件夹
5、重启myeclipse就一切正常了。

方式二:使用Eclipse安装向导

打开Eclipse
help->Software Updates->find and install(如果没有这个就用help->Software Updates->Add/Remove Software即可)
选择search for new features to install, Next
点击new remote site
输入name:subclipse 1.6.x,url:http://subclipse.tigris.org/update_1.6.x,点OK
或者:
Name: Subclipse 1.6.x (Eclipse 3.2+)    URL:  http://subclipse.tigris.org/update_1.6.x
    Name: Subclipse 1.4.x (Eclipse 3.2+)    URL:  http://subclipse.tigris.org/update_1.4.x
    Name: Subclipse 1.2.x (Eclipse 3.2+)    URL:  http://subclipse.tigris.org/update_1.2.x
    Name: Subclipse 1.0.x (Eclipse 3.0/3.1)    URL:  http://subclipse.tigris.org/update_1.0.x

选中subclipse,点击finish
一直NEXT,这里注意下,有些时候会出现 Subclipse Integration for Mylyn 3.x (Optional) (3.0.0) requires plug-in "org.eclipse.mylyn.tasks.core (3.0.0)", or compatible.错误,这个不要紧,在弹出框中选择subclipse,把Subclipse Integration for Mylyn 3.x选项去掉即可
Next一路安装完成!

二、Eclipse中使用SVN(以MyEclipse8.0为例)

1、共享项目(把本地的项目共享到subversion服务器上)
打开MyEclipse8.0,假设要共享projTest是项目名称
右键项目projTest->Team->Share Project->Svn,
单库模式下url填写svn://svn server address/,多库模式下url填写svn://svn server address/Repository1,其中Repository1是库的名称
next直到finish,proj1就被共享到svn服务器上了,但是代码并没上传,还需要commit一次
右键项目projTest,team->commit,项目内容就被上传到svn服务器了
2、签出项目(把svn服务器上的项目下载的到本地)
打开MyEclipse8.0
window->open perspective->svn repository explorer(如果没有在other里选择)
在左边空白处右键->new->repository location
单库模式下url填写svn://svnserveraddress/,多库模式下url填写svn://svnserveraddress/Repository1(同步骤二)
右键projTest->check out
next直到finish,该项目就被签出到本地,切换到java视图就能看到该项目了

### http://subclipse.tigris.org/files/documents/906/49280/site-1.8.22.zip

原文地址:https://www.cnblogs.com/zhang-pengcheng/p/4334098.html