文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>在Suse10下尝试dogtail(一个python的GUI测试工具..

在Suse10下尝试dogtail(一个python的GUI测试工具..

时间:2006-08-02  来源:icymoon

零 简介:
    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:[email protected]
$cvs login
Logging in to :pserver:[email protected]: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)
相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载