Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vc.distance takes forever #250

Open
jihun-im opened this issue Jun 18, 2018 · 0 comments
Open

vc.distance takes forever #250

jihun-im opened this issue Jun 18, 2018 · 0 comments

Comments

@jihun-im
Copy link

jihun-im commented Jun 18, 2018

The code below take forever when view_list and view_list2 is different:

#! /usr/bin/env python

import sys
import os
import hashlib
from com.dtmilano.android.viewclient import ViewClient

reload(sys)
sys.setdefaultencoding('UTF8')

# PyDev sets PYTHONPATH, use it
try:
    for p in os.environ['PYTHONPATH'].split(':'):
        if not p in sys.path:
            sys.path.append(p)
except:
    pass

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


def get_clickable_view_list(_view_list):
    result_view_list = []
    for each_view in _view_list:
        if each_view.isClickable():
            result_view_list.append(each_view)
    return result_view_list


def get_string_of_view_list(_view_list):
    string = ""
    for each_view in _view_list:
        string += str(each_view)
    return string


vc = ViewClient(*ViewClient.connectToDeviceOrExit(verbose=True))

view_list = vc.dump(sleep=0)
print(hashlib.sha1(get_string_of_view_list(view_list)).hexdigest())
for view in get_clickable_view_list(view_list):
    if "Chat" in view.getContentDescription():
        view.touch()

view_list2 = vc.dump(sleep=0)
print(hashlib.sha1(get_string_of_view_list(view_list2)).hexdigest())
print(get_string_of_view_list(view_list) == get_string_of_view_list(view_list2))

print(str(vc.distance(view_list, view_list2)))
# print(str(vc.hammingDistance(view_list, view_list2)))
# print(str(vc.levenshteinDistance(view_list, view_list2)))

If I CTRL+C the result is like this:

jihunimimac:examples jihun.im$ python playground.py
Connecting to a device with serialno=.* with a timeout of 60 secs...
Connected to device with serialno=.*
Actual device serialno=ENU7N15A30003855
6b766238ea1b51f2b18ac62150e61ba27be21ba7
578e476a82026b3e74a5bbefe17b5682c0e299f1
False
^CTraceback (most recent call last):
File "playground.py", line 58, in

File "/usr/local/lib/python2.7/site-packages/com/dtmilano/android/viewclient.py", line 4195, in distance
return ViewClient.__levenshteinDistance(s1, s2)/t
File "/usr/local/lib/python2.7/site-packages/com/dtmilano/android/viewclient.py", line 4296, in __levenshteinDistance
cost = 0 if s[i-1] == t_j else 1
KeyboardInterrupt

Additionally, hammingDistance and levenshteinDistance has following Error even though I gave 2 arguments!:

Traceback (most recent call last):
File "playground.py", line 53, in
print(str(vc.hammingDistance(view_list, view_list2)))
TypeError: hammingDistance() takes exactly 2 arguments (3 given)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant