#! /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 ']
Failed t 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 ")