在某些 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
变量之后,它仍然保持应用程序加载时收到的值。 None
refresh()
LoadingApp
None
所以我的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
我设置 DEBUG
,DEBUG_RECEIVED
并DEBUG_TREE
进入viewclient.py
。TRUE
这些是我在文件中所做的唯一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 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()
功能后完美!