0

在某些 Android 应用程序上运行我的脚本时AndroidViewClient,我区分了一个表示应用程序仍在加载的视图。
我开始一个While带有内部延迟和刷新的循环,如下所示:

while LoadingApp is not None:  
    print "Application is still not ready.\nWaiting 5 seconds"  
    print The Application is still loading...  
    time.sleep(5)  
    refresh()

refresh()函数执行整个视图转储:

def refresh():  
    vc.dump(window='-1')  
    launcherIcon = vc.findViewById("fourier.milab:id/launcherIcon")  
    graphIcon = vc.findViewById("fourier.milab:id/graphIcon")  
    tableIcon = vc.findViewById("fourier.milab:id/tableIcon")  
    ...  
    LoadingApp = vc.findViewWithAttribute("text", u'Loading\nMiLAB')   

最后应用程序完全打开,LoadingApp不再出现视图。

我想当应用程序打开但变量 never got时执行第一个LoadingApp变量之后,它仍然保持应用程序加载时收到的值。 Nonerefresh()LoadingAppNone

所以我的While循环变得无限

我想这是AndroidViewClient错误。

如果在应用程序打开时使用它会在第一次完成时 LoadingApp = vc.findViewWithAttributeOrRaise("text", u'Loading\nMiLAB')引发异常。refresh()

所以AndroidViewClient现在找不到这个视图(这是正确的!)但它的容器(变量)仍然包含旧的、错误的、未更新的值。

更新

我的While循环代码是

f = open('my_text.txt','w+')
while LoadingMiLAB is not None:
    print "MiLAB is still not ready.\nWaiting 5 seconds"
    print LoadingMiLAB
    for key, value in LoadingMiLAB.map.iteritems():
        print key, value
        f.write(key)
        f.write('\t')
        f.write(' '.join(map(str, value)))
        f.write('\n')
    f.write('\n\n\n')
    print "\n\n\n"
    time.sleep(5)
    refresh()  

我收到的输出是:

index   2
selected    f a l s e
checked f a l s e
clickable   f a l s e
package f o u r i e r . m i l a b
text    L o a d i n g 
 M i L A B
long-clickable  f a l s e
enabled t r u e
bounds  (550, 418) (729, 491)
content-desc    
focusable   f a l s e
focused f a l s e
uniqueId    i d / n o _ i d / 7
checkable   f a l s e
resource-id f o u r i e r . m i l a b : i d / r a t e T e x t V i e w
password    f a l s e
class   a n d r o i d . w i d g e t . T e x t V i e w
scrollable  f a l s e  

这是我在加载应用程序时收到的,当它已经加载时,甚至当我已经关闭了应用程序时。

所以我认为问题是:当视图不再出现时, LoadingMiLAB视图数据不会被接收到的对象覆盖。None

我设置 DEBUGDEBUG_RECEIVEDDEBUG_TREE进入viewclient.pyTRUE

这些是我在文件中所做的唯一viewclient.py更改adbclient.py

我不使用View.setVisibility(View.GONE)或更改任何其他标志/参数。

我使用您的culebra脚本及其默认设置。我在那里更改的唯一参数是创建的(输出)脚本文件名和目标。

当我添加print vc.findViewWithText(u'Loading\nMiLAB').getVisibility()代码时,我-1在加载应用程序并显示视图时看到。

当应用程序加载(并且视图消失)时,我收到了

AttributeError: 'NoneType' object has no attribute 'getVisibility'  

我用过vc.findViewWithText(u'Loading\nMiLAB').getVisibility(),没有vc.findViewWithTextOrRaise(u'Loading\nMiLAB').getVisibility()

因为这会在加载应用程序并且不再出现视图时引发错误。

我正在使用Windows 7OS PC

UPD2

While我在循环中 添加了一个异常。

while LoadingMiLAB:
    print "MiLAB is still not ready.\nWaiting 5 seconds"
    time.sleep(5)
    refresh()
    try:
        LoadingMiLAB = vc.findViewWithText(u'Loading\nMiLAB')
    except EmptyLoadingMiLABException:
        print "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"  

现在我的脚本退出循环并在视图不再出现While时继续继续。LoadingMiLAB

最终更新

这是我的错。我的refresh()函数实际上创建了local变量,而不是刷新了global视图状态。在将它们声明为global我的refresh()功能后完美!

4

2 回答 2

1

这是我的错。我的refresh()函数实际上创建了局部变量,而不是刷新了全局视图状态。在将它们声明为global我的refresh()功能后完美!

于 2014-05-28T15:54:51.083 回答
0

我认为您的 while 循环应该更像(顺便说一句,变量通常以小写字母开头,不要与类混淆)

while True:
    print "MiLAB is still not ready.\nWaiting 5 seconds"
    time.sleep(5)
    refresh()
    try:
        vc.findViewWithTextOrRaise(u'Loading\nMiLAB')
    except ViewNotFoundException:
        break
于 2014-05-22T21:08:33.263 回答