开发者

Why does MonkeyRunner fail when called using TeamCity

I have a monkeyrunner script that connects to an Android device and deploys an APK on it.

serial = '12345JKL'
device = MonkeyRunner.waitForConnection(deviceId=serial)
device.installPackage(path_to_apk)

This works flawlessly when I execute the script using the Windows command shell.

"C:\dev\android\tools\monkeyrunner.bat" "C:\dev\my_script.py" -psome_parameter

The problem is that I want to have my_script.py executed by a TeamCity (Enterprise 6.0.3) build configuration on the same PC: this fails. Please find the stack trace here: http://pastebin.com/CjWy95c3

First I thought that TC was messing with the parameters of the script. But the command from the TC build log

[00:55:12]: Starting: "C:\dev\android\tools\monkeyrunner.bat" "C:\dev\my_script.py" -psome_parameter
in directory: C:\some_dir

was the same as in the command shell and accordingly the script could connect to the device and worked fine when I copied the command into a command shell while C:\some_dir was my current directory.

I was not able to reprodu开发者_如何学编程ce this error outside of TC.

I want to emphasize that this all happens on the same PC (Win 7 x64). The script works when executed from the command shell but fails (always when trying to connect to a device) when triggered by the TC build configuration.

I can't think of a reason why this happens and would be very happy if somebody could point me in the right direction.

Many thanks in advance

Edit: As it turns out the problem isn't limited to MonkeyRunner.waitForConnection() but also occurs when calling MonkeyRunner.sleep(5). Stacktrace

Can it be that MonkeyRunner and TeamCity don't go along well with each other?


This is probably caused by a problem with your imports. The problem with your imports is likely because of the way that TeamCity calls MonkeyRunner. I would guess that it has to do with the current directory being messed up. Try using

import os
os.chdir("path")

to change your current directory at the top of your .py script. (Before you import monkeyrunner) I would try changing it to the directory with MonkeyRunner.


After a colleague and I have investigated the problem for three days, we could not find the source of this problem. But when we used another machine as the build agent, the issue was gone. We still don't know what caused this NullPointerException.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜