如何从真机运行monkeyrunner脚本?

发布于 2024-12-16 22:50:28 字数 783 浏览 0 评论 0原文

我已经编写了可以在模拟器中运行的代码。如何让它在真实设备中工作?只需连接设备并更改位置(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')

I have written this code which is working in the emualator. How do I get it to work in a real device? Is just connecting the device and changing the location (device location of apk) enough?

# 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')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-12-23 22:50:28

看起来它应该像现在一样在真实设备上运行。如果您遇到问题,您可能需要尝试添加“MonkeyRunner.sleep(n)”(其中 n 是数字)语句。有些设备不会等到上一个任务完成才请求下一个任务。

This looks like it should work on a real device just the way it is right now. If you are experiencing issues, you might want to try adding "MonkeyRunner.sleep(n)" (where n is a number) statements. Some devices do not wait for the last task to finish before asking for the next one.

梦幻的味道 2024-12-23 22:50:28

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

You might also try configuring the package and activity before you connect to the device.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文