I am trying to implement Android viewclient and Monkeyrunner together as i want to take snapshot load image and compare files using Monkeyrunner and run viewbased scripts using AndroidViewClient , can you please let me know how to do that or if there is a way we can implement image loading and comparision from viewclient itself that would be fine too.
Asked
Active
Viewed 349 times
1 Answers
1
You can use AdbClient.sameAs()
as a replacement and in such case you don't need Monkeyrunner at all.
For example to print the difference between 2 screenshots (using culebra
to generate the script, although you have to add the last lines manually):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014 Diego Torres Milano
Created on 2015-08-11 by Culebra v10.6.1
__ __ __ __
/ \ / \ / \ / \
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
| / \ / \ / \ / \ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
import time
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)
img1 = device.takeSnapshot(reconnect=True)
time.sleep(60)
img2 = device.takeSnapshot(reconnect=True)
print 'percent=', device.percentSame(img1, img2)
There are also other ways of comparing two View trees, not just using image comparison, take a look at ViewClient.distance(tree1, tree2)
.

Diego Torres Milano
- 65,697
- 9
- 111
- 134
-
I Tried doing that but i got an error back saying 'str' object has no attribute 'size' i declared two variables with image location and did try AdbClient.Sameas(im1, im2) – Pavan Aug 11 '15 at 20:13
-
Hi dtmilano, i never got Culebra to work on my system , can you please tell me if there are any specific steps i have to follow inorder to get that to work also when i was trying code above it give me error module named Java not found. – Pavan Aug 13 '15 at 14:57
-
Java is not mentioned anywhere in the script, so is something related to your env. Are you running it with python? – Diego Torres Milano Aug 13 '15 at 16:44
-
Yes i am i used python program.py and it gave me error Module java not found. – Pavan Aug 13 '15 at 22:08
-
Try to find the line that causes the problem by commenting out parts of the script. Do `dump` and `culebra` work? Which OS? – Diego Torres Milano Aug 14 '15 at 00:43
-
Hi dtmilano, i am using windows, Script you gave me is working fine when we are comparing 2 screen shots taken in the script it self but when trying to compare device.takeSnapshot() in the scrip to image file stored in the system script is giving me error File "HVACverifyfrontclimate.py", line 128, in onoff Percent = device.percentSame(img1, img2) File "C:\Python27\lib\site-packages\com\dtmilano\android\adb\adbclient.py", li ne 798, in percentSame size_x1, size_y1 = image1.size AttributeError: 'str' object has no attribute 'size' error can you please look into this . – Pavan Aug 20 '15 at 22:49