0

When we use MonkeyRunner to do the Android UI analysis, we can use the device.getHierarchyViewer().focusedWindowName to get the current screens' window name quickly.

Then we can use the window name to do some basic UI judgement or analysis.

And for AndroidViewClient ( git@github.com:dtmilano/AndroidViewClient.git ), does it have the similar usage? Thanks.

device = MonkeyRunner.waitForConnection()
hViewer = device.getHierarchyViewer()
win_name = hViewer.getFocusedWindowName()
Chris Forever
  • 678
  • 1
  • 5
  • 18

1 Answers1

1

I think it's answered here.

However, I think, due to popular demand, I will be adding a more straightforward method to AdbClient. Perhaps AdbClient.getFocusedWindowName() to be consistent. This Window has no relationship with the View hierarchy, that's why I think it doesn't fit as a exposed method to ViewClient.

Comments are welcome.

EDIT

Good news, AndroidViewClient 8.27.1 now features AdbClient.getWindows(), AdbClient.getFocusedWindows() and AdbClient.getFocusedWindowName().

You can use it like here:

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014  Diego Torres Milano
Created on 2015-01-05 by Culebra v8.27.1
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''


import re
import sys
import os

try:
    sys.path.insert(0, os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient


kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)

print device.getWindows()
print device.getFocusedWindow()
print device.getFocusedWindowName()

BTW, I would be interested in knowing how you use these features. Is it to check preconditions?

Community
  • 1
  • 1
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134