cannot use raw_input if monkeyrunner is included in python script

寵の児 提交于 2019-12-07 18:08:55

问题


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.


回答1:


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!




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!