【问题标题】:How to run from the real device monkeyrunner script?如何从真机monkeyrunner脚本运行?
【发布时间】:2012-05-15 12:21:22
【问题描述】:

我已经编写了在模拟器中运行的代码。如何让它在真实设备中工作?只是连接设备并更改位置(apk的设备位置)就够了吗?

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage

# Connect to the current device
device = MonkeyRunner.waitForConnection()

# Install package
device.installPackage('C:/android-sdk-windows/tools/lib/purchase.apk')

# Run activity
device.startActivity(component='com.mobilenetwork.purchase/.StartPage ')

# Importing time
import time

# Waiting for 10 secs to be launched on the emulator:
time.sleep(10)
device.press('KEYCODE_BUTTON_SELECT','DOWN','')

# Screenshot
time.sleep(10)
result = device.takeSnapshot()

# Writes the screenshot to a file
result.writeToFile('G:\\Screenshot\\screen_shot.png','png')

【问题讨论】:

    标签: monkeyrunner


    【解决方案1】:

    这看起来应该像现在一样在真实设备上工作。如果您遇到问题,您可能想尝试添加“MonkeyRunner.sleep(n)”(其中 n 是数字)语句。有些设备在请求下一个任务之前不会等待最后一个任务完成。

    【讨论】:

    • 对不起!!!!!!我忘记发帖了。。当我连接设备时,它会自动工作。谢谢
    【解决方案2】:

    您也可以在连接到设备之前尝试配置包和活动。

    【讨论】:

      猜你喜欢
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 2013-12-13
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多