I want to input some values in my python script. Part of my code is:
import os,sys,subprocess,shlex,time
from com.android.monkeyrunner import MonkeyRunner
import com.android.monkeyrunner.MonkeyDevice
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
user = raw_input("enter your username")
print user
When i am executing the code as "monkeyrunner camautoopen.py" Then i can only input username. But i cannot print it.
when my code is :
import os,sys,subprocess,shlex,time
user = raw_input("enter your username")
print user
and i execute the script as python camautoopen.py , then i get the desired result.
Are you using Mac OS X? I had the same problem, and I found the fix here: https://code.google.com/p/android/issues/detail?id=56318
I basically needed to swap out Jython with a newer version. Hope that helps!
you can either include the libraries of monkey and write the script by your own in java
import eu.fbk.se.androidmonkey.Monkey;
import android.app.Instrumentation;
import android.content.pm.PackageManager;
import android.test.ActivityInstrumentationTestCase2;
import android.view.Display;
public class MonkeyLoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {
private int NUM_EVENTS = 320;
public MonkeyLoginActivityTest() {
super(LoginActivity.class);
// TODO Auto-generated constructor stub
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
}
public void testMonkeyEvent() {
Display display = getActivity().getWindowManager().getDefaultDisplay();
Instrumentation inst = getInstrumentation();
PackageManager pm = getActivity().getPackageManager();
Monkey monkey = new Monkey(display,"com.wisemoo.tickleboards.dev.activities", inst, pm);
// Generate and fire a random event.
for (int i = 0; i < NUM_EVENTS; i++) {
monkey.nextRandomEvent();
}
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
}
来源:https://stackoverflow.com/questions/26032674/cannot-use-raw-input-if-monkeyrunner-is-included-in-python-script