MR_Android view client source code(2)

來源:互聯網
上載者:User

#!/usr/bin/env monkeyrunner
'''
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.tuangou.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()

#touchProject = vc.findViewWithTextOrRaise('', root)
touchProject = vc.findViewByIdOrRaise('id/title_right_tv')
touchProject.touch()
# wait for screenshot to save
mr.sleep(2);

# Takes a screenshot
result1 = device.takeSnapshot()
result1.writeToFile('shot11.png','png')
# wait for 3 seconds
mr.sleep(3);

在 android platform 2.2上運行出現以下警告:

AndroidViewClient/AndroidViewClient/src/com/dtmilano/android/viewclient.py:763: UserWarning: Unsupported Android version 8
  warnings.warn("Unsupported Android version %d" % self.build[VERSION_SDK_PROPERTY])

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.