【问题标题】:`AndroidViewClient` doesn't update disappeared views?`AndroidViewClient` 不会更新消失的视图?
【发布时间】:2014-07-08 18:40:50
【问题描述】:

在某些 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 视图不再出现。

我想LoadingApp 变量在应用程序打开时执行第一个refresh() 后变为None,但LoadingApp 变量从未得到None,它仍然保持应用程序加载时收到的值。

所以我的While 循环变得无限

我想这是AndroidViewClient 错误。

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

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

UPD

我的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 对象覆盖,当视图不再出现时。

我将viewclient.py 中的DEBUGDEBUG_RECEIVEDDEBUG_TREE 设置为TRUE

这些是我在viewclient.pyadbclient.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 7 OS 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() 函数完美运行!

【问题讨论】:

  • 添加print LoadingApp 看看里面有什么
  • 已经这样做了。即使在视图已经消失的情况下完成了几次refresh(),它也会打印该视图出现在屏幕上时第一次收到的值
  • 另外,你为什么用vc.findViewWithAttribute()而不是vc.findViewWithText()
  • 好吧,我从那天就离开了这个表格,学习了根据参数查找视图的不同方法,对不起;)无论如何,当我使用时,现象(错误)并没有改变vc.findViewWithText()
  • 尝试在 viewclient.py 中启用 DEBUG、DEBUG_RECEIVED 和 DEBUG_TREE 并捕获输出

标签: android automation androidviewclient


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我认为你的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
    

    【讨论】:

    • 没有。在这种情况下,它将捕获findViewWithTextOrRaise 上的异常,并且应用程序将被终止,而我需要它只是从While 循环中退出。我对此进行了测试。
    • 此外,它必须是While LoadingMiLAB 而不是While TRUE,因为只有在出现LoadingMiLAB 视图时我才想进入这个循环。仅当应用程序在连接到外部 BT 设备时出现问题时才会显示此视图....
    • 通常这个视图根本不会出现,所以我希望只有在连接到外部配对 BT 设备出现问题/延迟的情况下才进入这个循环。
    猜你喜欢
    • 2016-10-24
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多