dtmilano / AndroidViewClient

Android ViewServer and ADB client
Apache License 2.0
1.62k stars 347 forks source link

view.device is null(?) #142

Closed gdobra closed 9 years ago

gdobra commented 9 years ago

view.touch() throws the error:

..., line 922, in touch self.device.touch(x, y, eventType=eventType) AttributeError: 'NoneType' object has no attribute 'touch'

seems that the device field of every view is None; if I explicitely set it to a valid value(obtained on connect), the error does not happen - the touch is done.

dtmilano commented 9 years ago

AVC/culebra version? Android version? Steps to reproduce?

gdobra commented 9 years ago

AVC, even the latest not using culebra Android API 18, ARM, SDK 22.3

steps to reproduce: connect get a dump touch a view, whatever that is

-seems that the device field of some(all?) views is None

dtmilano commented 9 years ago
    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        print "API:", self.device.getSdkVersion()
        self.vc.dump(window=-1)
        self.vc.findViewWithTextOrRaise(u'9').touch()

This works as expected, prints API: 18 and touches the 9 (running Calculator).

gdobra commented 9 years ago

maybe I'm doing it wrong, but:

vc = ViewClient(..) dump = vc.dump(timeout = 2) root = dump[0] for item in root.children: print item.getText(), item.getClass(), item.device

will print: something, anotherthing, None

and I recursively try to descend the hierarchy, starting with the first node in dump as the root node. Aren't the children nodes pointing to objects in the list returned from vc.dump()? or are they some (shallow) copy of them?

gdobra commented 9 years ago

So, if I do:

for item in vc.dump(timeout = 2): print item.getText(), item.getClass(), item.device

I get everything ok, each view has a valid device reference

But if I do:

recursiveTraverse(vc.dump(timeout = 2)[0]), where recursiveTraverse is a function which does what its name implies(as already stated in a previous comment), seems that dump[0] item is copied(?) with no device information.

dtmilano commented 9 years ago

I tried this and works:

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        dump = self.vc.dump(window=-1)
        root = dump[0]
        for item in root.children:
            print item.getText(), item.getClass(), item.device

giving this output:


3 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x1076317a0>

 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x1076317a0>

 android.support.v4.view.ViewPager
<com.dtmilano.android.adb.adbclient.AdbClient instance at 0x1076317a0>

.

----------------------------------------------------------------------

Ran 1 test in 3.519s

OK

On Fri, May 22, 2015 at 12:57 PM, Grigore Dobra notifications@github.com wrote:

So, if I do:

for item in vc.dump(timeout = 2):

— Reply to this email directly or view it on GitHub https://github.com/dtmilano/AndroidViewClient/issues/142#issuecomment-104712834 .

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients

dtmilano commented 9 years ago

I didn't mention it, but it's a

class CulebraTests(CulebraTestCase):
    ...

On Fri, May 22, 2015 at 2:49 PM, Diego Torres Milano dtmilano@gmail.com wrote:

I tried this and works:

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        dump = self.vc.dump(window=-1)
        root = dump[0]
        for item in root.children:
            print item.getText(), item.getClass(), item.device

giving this output:


3 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x1076317a0>

 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x1076317a0>

 android.support.v4.view.ViewPager
<com.dtmilano.android.adb.adbclient.AdbClient instance at 0x1076317a0>

.

----------------------------------------------------------------------

Ran 1 test in 3.519s

OK

On Fri, May 22, 2015 at 12:57 PM, Grigore Dobra notifications@github.com wrote:

So, if I do:

for item in vc.dump(timeout = 2):

— Reply to this email directly or view it on GitHub https://github.com/dtmilano/AndroidViewClient/issues/142#issuecomment-104712834 .

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients

dtmilano commented 9 years ago

And also

#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014  Diego Torres Milano
Created on 2015-05-22 by Culebra v10.5.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

TAG = 'CULEBRA'

_s = 5
_v = '--verbose' in sys.argv

kwargs1 = {'ignoreversioncheck': False, 'verbose': False,
'ignoresecuredevice': False}
device, serialno = ViewClient.connectToDeviceOrExit(**kwargs1)
kwargs2 = {'compresseddump': True, 'startviewserver': True,
'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled':
True}
vc = ViewClient(device, serialno, **kwargs2)
#vc.dump(window='-1') # FIXME: seems not needed

#dump = vc.dump(timeout = 2)
dump = vc.dump()
root = dump[0]
for item in root.children:
    print item.getText(), item.getClass(), item.device

gives


3 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x101945d40>

 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x101945d40>

 android.support.v4.view.ViewPager
<com.dtmilano.android.adb.adbclient.AdbClient instance at 0x101945d40>

On Fri, May 22, 2015 at 2:50 PM, Diego Torres Milano dtmilano@gmail.com wrote:

I didn't mention it, but it's a

class CulebraTests(CulebraTestCase):
    ...

On Fri, May 22, 2015 at 2:49 PM, Diego Torres Milano dtmilano@gmail.com wrote:

I tried this and works:

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        dump = self.vc.dump(window=-1)
        root = dump[0]
        for item in root.children:
            print item.getText(), item.getClass(), item.device

giving this output:


3 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x1076317a0>

 android.widget.EditText <com.dtmilano.android.adb.adbclient.AdbClient
instance at 0x1076317a0>

 android.support.v4.view.ViewPager
<com.dtmilano.android.adb.adbclient.AdbClient instance at 0x1076317a0>

.

----------------------------------------------------------------------

Ran 1 test in 3.519s

OK

On Fri, May 22, 2015 at 12:57 PM, Grigore Dobra <notifications@github.com

wrote:

So, if I do:

for item in vc.dump(timeout = 2):

— Reply to this email directly or view it on GitHub https://github.com/dtmilano/AndroidViewClient/issues/142#issuecomment-104712834 .

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients

Have you read my blog ? http://dtmilano.blogspot.com android junit tests ui linux cult thin clients