python gui测试工具_在Suse10下尝试dogtail(一个python的GUI测试工具..
你的位置:
技術文檔
-> Python
-> 文檔詳情
在Suse10下嘗試dogtail(一個python的GUI測試工具..
零 簡介:
DogTail是一個用python寫的,自動測試GUI程序的工具。使用AT(Accessibility techno logies)技術與桌面應用程序交互。可以模擬和替代部分人工測試GUI的操作。但目前為止還 不能模擬人工操作的一些錯誤情況。現在只支持GNOME和GTK+
一 下載與依賴問題:
下載地址:http://people.redhat.com/zcerza/dogtail/downloads.html
依賴:
* AT-SPI-enabled desktop (GNOME at this point in time).
* Python 2.3 or higher (available through your distribution).
* ImageMagick 6.2 or higher (available through your distribution).
* rpm-python or python-apt (available through your distribution).
* ElementTree for Python (available through your distribution).
* pyspi - Python AT-SPI bindings.
順便說一下我所用的環境:
Suse 10.0
Python 2.4.1
二 安裝過程簡記
(1)依賴的包/工具
*? AT-SPI
找了rpm包,確認裝了at-spi和at-spi-devel。
$rpm -qa | grep at-spi
at-spi-devel-1.6.6-2
at-spi-1.6.6-2
*? ImageMagick是一個能夠支持多種圖片格式的讀寫的工具
http://www.imagemagick.org/script/index.php
這樣檢測本機是否已經安裝了ImageMagick
$convert -version
Version: ImageMagick 6.2.3 09/13/05 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2005 ImageMagick Studio LLC
這里ImageMagick的版本是6.2.3
*? rpm-python or python-apt
對于Suse,使用$rpm -qa | grep rpm-python查找即可
*? ElementTree for Python
這是處理XML的一個工具,據說效率不錯
本機已經安裝了python-elementtree-1.2.6-2
*? pyspi
主頁上給出的下載鏈接無效,從gnome的網站上下載CVS的版本
$export CVS_RSH=ssh
$export CVSROOT=:pserver:anonymous@anoncvs.gnome
$cvs login
Logging in to :pserver:anonymous@anoncvs.gnome.org:2401/cvs/gnome
CVS password:
$cvs -z3 co pyspi
...
注1: -z3只是壓縮級別,z9為最大
注2:? 要使用下載來的CVS的源碼,可能需要gettextize, intltoolize, libtoolize, aclo cal, autoheader, automake & autoconf
INSTALL文件寫得好簡單,我執行不過去源碼目錄下的setup.py,讀setup.py查找原因。
$./setup.py install --prefix=/usr/local/
Traceback (most recent call last):
File "./setup.py", line 12, in ?
raise ImportError, inst
ImportError: No module named Pyrex.Distutils
出現這個錯誤的原因是from Pyrex.Distutils import build_ext時候找不到Pyrex.Distuti ls模塊。
注:Pyrex lets you write code that mixes Python and C data types any way you wan t, and compiles it into a C extension for Python.
對于使用python2.4的用戶,FAQ里還有這樣一條要注意:
Q: I can't get pyspi to build using Python 2.4!
A:If you see an error like:
TypeError: swig_sources() takes exactly 2 arguments (3 given)
then you probably have Pyrex 0.9.3 or earlier installed. Get Pyrex 0.9.3.1 - it fixes the incompatibility with Python 2.4.
安裝Pyrex(倒霉的網速...)
$tar -zvxf Pyrex-0.9.3.1.tar.gz
$cd Pyrex-0.9.3.1
$python setup.py install
繼續安裝pyspi
./setup.py install --prefix=/usr/local
(2)下載,安裝dogtail
前面的CVS環境變量不變,$cvs -z3 co dogtail即可
$cd dogtail
$./setup.py install --prefix=/usr
居然裝上了...
三 測試樣例
首先使桌面支持AT-SPI
gconftool-2 --set --type bool /desktop/gnome/interface/accessibility true
然后重起gnome即可。
下載測試程序
http://people.redhat.com/zcerza/dogtail/media.html
這個頁面上有測試程序和演示的flash.flash不錯。 :)
(1) gedit的測試程序: gedit-test-utf8-procedural-api.py
$ ./gedit-test-utf8-procedural-api.py
Creating logfile at /tmp/dogtail/logs/gedit-test-utf8-procedural-api_20060802-13 2321 ...
Detecting distribution: SuSE (or derived distribution)
Traceback (most recent call last):
File "./gedit-test-utf8-procedural-api.py", line 9, in ?
from dogtail.procedural import *
File "/usr/lib/python2.4/site-packages/dogtail/procedural.py", line 18, in ?
import tree
File "/usr/lib/python2.4/site-packages/dogtail/tree.py", line 64, in ?
import predicate
File "/usr/lib/python2.4/site-packages/dogtail/predicate.py", line 8, in ?
from i18n import TranslatableString
File "/usr/lib/python2.4/site-packages/dogtail/i18n.py", line 10, in ?
import distro
File "/usr/lib/python2.4/site-packages/dogtail/distro.py", line 313, in ?
packageDb = distro.packageDb
NameError: global name 'distro' is not defined
發現這個錯誤是由于/usr/lib/python2.4/site-packages/dogtail/distro.py中,當判斷OS 為SuSE時沒有初始化distro這個全局變量引起的,定義的相關類為空,看來是還沒有實現了 ...T_T,自己改了代碼,初始化的部分直接用了Redhat/Fedora的_RpmPackageDb(),如下:
vi /usr/lib/python2.4/site-packages/dogtail/distro.py
Line: 260
#===added by icymoon====
class SuSE(Distro):
"""
Class representing one of the SuSE or SuSE-derived distributions, added by i cymoon
Using RpmPackageDb, the one belongs Redhat OR Fedora
"""
def __init__(self):
self.packageDb = _RpmPackageDb()
#===added end===========
后面初始化的部分:
......
elif os.path.exists ("/etc/SuSE-release"):
print "SuSE (or derived distribution)"
distro = SuSE()
繼續...
$./gedit-test-utf8-procedural-api.py
Creating logfile at /tmp/dogtail/logs/gedit-test-utf8-procedural-api_20060802-13 4604 ...
Detecting distribution: SuSE (or derived distribution)
Traceback (most recent call last):
File "./gedit-test-utf8-procedural-api.py", line 9, in ?
from dogtail.procedural import *
File "/usr/lib/python2.4/site-packages/dogtail/procedural.py", line 18, in ?
import tree
File "/usr/lib/python2.4/site-packages/dogtail/tree.py", line 78, in ?
raise ImportError, "Error importing the AT-SPI bindings"
ImportError: Error importing the AT-SPI bindings
是/usr/lib/python2.4/site-packages/dogtail/tree.py中import atspi拋出的異常
$cp atspi.so /usr/lib/python2.4/site-packages/
繼續...
$ ./gedit-test-utf8-procedural-api.py
Creating logfile at /tmp/dogtail/logs/gedit-test-utf8-procedural-api_20060802-13 5059 ...
Detecting distribution: SuSE (or derived distribution)
Warning: AT-SPI's desktop is visible but it has no children. Are you running any? AT-SPI-aware applications?
Traceback (most recent call last):
File "./gedit-test-utf8-procedural-api.py", line 18, in ?
dogtail.i18n.loadTranslationsFromPackageMoFiles('gedit')
File "/usr/lib/python2.4/site-packages/dogtail/i18n.py", line 248, in loadTran slationsFromPackageMoFiles
load(packageName, language, getDependencies)
File "/usr/lib/python2.4/site-packages/dogtail/i18n.py", line 224, in load
for moFile in getMoFilesForPackage(packageName, language, getDependencies):
File "/usr/lib/python2.4/site-packages/dogtail/i18n.py", line 209, in getMoFil esForPackage
for dep in distro.packageDb.getDependencies(packageName):
File "/usr/lib/python2.4/site-packages/dogtail/distro.py", line 111, in getDep endencies
for requirement in header[rpm.RPMTAG_REQUIRES]:
AttributeError: 'module' object has no attribute 'RPMTAG_REQUIRES'
...亂改代碼的報應啊 T_T
繼續改吧...
$/usr/lib/python2.4/site-packages/dogtail/distro.py
Line: 111
改成for requirement in header[rpm.RPMTAG_REQUIRENAME]:,用rpm.RPMTAG_REQUIRENAME 代替了rpm.RPMTAG_REQUIRES
繼續吧,心里越來越沒譜了 -_-b 因為我并不了解SuSE與Redhat在使用rpm上有什么差異.. 何況這應該和python相關的.
$ ./gedit-test-utf8-procedural-api.py
這次總算運行了,跳出個gedit,不過要有data/UTF-8-demo.txt這個文件,這里我就不再詳 細描述這個無聊的錯誤了。到了保存文件那步,跳出來的錯誤是這樣的:
Traceback (most recent call last):
File "./gedit-test-utf8-procedural-api.py", line 50, in ?
click('Save')
File "/usr/lib/python2.4/site-packages/dogtail/procedural.py", line 280, in __? call__
Action.__call__(self, name = name, roleName = roleName, description = descri? ption, delay = delay)
File "/usr/lib/python2.4/site-packages/dogtail/procedural.py", line 212, in __? call__
FocusWidget.__call__(self, name = name, roleName = roleName, description = d? escription)
File "/usr/lib/python2.4/site-packages/dogtail/procedural.py", line 121, in __? call__
raise FocusError, predicate.debugName
dogtail.procedural.FocusError: child with name="Save"
這樣拋出的異常應該是應用程序本身的問題,手動用了一下gedit,按照測試腳本中的步驟 進行操作,發現在點擊Save的時候本身就是報這樣的錯誤:
gtk_file_system_path_is_local: assertion `path != NULL' failed
不幸查到這是一個已知bug...是libgnomeui中的一個已經fix了的bug...多災多難的test啊 ,如果更新這個庫那可是要折騰一堆東西地~~
BTW: 順便從源碼中發現了一個問題,這個測試是調用rpm相關的接口來做的...
我決定放棄這個測試了...
(2)...明天繼續
四 參考:
http://people.redhat.com/zcerza/dogtail/
http://people.redhat.com/zcerza/dogtail/media.html
哪位在看相同的東西?是否遇到了相同或不同的問題?歡迎討論~
(To be continued)
作者: icymoon
發布時間: 2006-08-02
總結
以上是生活随笔為你收集整理的python gui测试工具_在Suse10下尝试dogtail(一个python的GUI测试工具..的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: o2o模式和b2c模式的不同点是什么?
- 下一篇: Web开发分享qq、微信组件-百度分享