#!/usr/bin/env monkeyrunner
# -*- coding:utf-8 -*-
'''
Copyright (C) 2012 Diego Torres Milano
Created on Feb 3, 2012
@author: diego
'''
import sys
import os
# this must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails
#Actual device serialno=emulator-5554
try:
ANDROID_VIEW_CLIENT_HOME = os.environ['ANDROID_VIEW_CLIENT_HOME']
except KeyError:
print >>sys.stderr, "%s: ERROR: ANDROID_VIEW_CLIENT_HOME not set in environment" % __file__
sys.exit(1)
sys.path.append(ANDROID_VIEW_CLIENT_HOME + '/src')
from com.dtmilano.android.viewclient import ViewClient
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner as mr, MonkeyDevice as md
#starting script
print "start"
# Connects to the current device, returning a MonkeyDevice object
device, serialno = ViewClient.connectToDeviceOrExit(30,"emulator-5554")
#device connected
print "connection started"
# sets a variable with the package's internal name
package = 'com.tuangoui.taobao'
# sets a variable with the name of an Activity in the package
activity = '.activities.StartActivity'
# sets the name of the component to start
runComponent = package + '/' + activity
# Runs the component
device.startActivity(component=runComponent)
#device set to sleep for 4 seconds
print "wait for 10 seconds"
# first screen shot event
mr.sleep(10);
vc = ViewClient(device, serialno)
vc.dump()
root = vc.getRoot()
for i in range(1,50):
id_list=vc.findViewByIdOrRaise('id/no_id/%d'%i)
print id_list.getText().encode("utf-8")