3

我打算使用monkeyrunner脚本来做自动化测试用例,我想使用robotframework(我对robotium不感兴趣)。我在http://blog.mykhailo.com/2011/02/how-to-sikuli-and-robot-framework.html看到了一个使用机器人框架自动化 sikuli 脚本的优秀教程

有没有办法用robotframework和monkeyrunner做类似的事情?

这是我的示例monkeyrunner 脚本,它在使用monkeyrunner 调用时正确执行。

from __future__ import with_statement
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

def testCase() :
    device = MonkeyRunner.waitForConnection()
    result2 = device.takeSnapshot()
    # Writes the screenshot to a file
    result2.writeToFile("scr.png","png")

def my_keyword():
    print 'Hello, world!'

if __name__ == '__main__':
    testCase()

我想用 roboframework 调用同样的方法。我正在尝试以下。我不确定以下调用是否正确,我只是从 sikuli 自动化示例中复制并修改它。

monkey_jar=/home/user/android-sdks/tools/lib/monkeyrunner.jar
guava_jar=/home/user/android-sdks/tools/lib/guavalib.jar
java -cp "robotframework-2.7.4.jar:$monkey_jar:$guava_jar" -Dpython.path="/home/user/android-sdks/tools/lib/" \
org.robotframework.RobotFramework --pythonpath=./  --outputdir=results --loglevel=TRACE $1

当我这样做时,我收到以下错误。

 Importing test library 'MyLibrary' failed: NoClassDefFoundError: Could not initialize class com.android.monkeyrunner.MonkeyDevice
java.lang.NoClassDefFoundError: 
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at MyLibrary$py.f$0(/home/user/automation/DemoScripts/MyLibrary.py:9)
    at MyLibrary$py.call_function(/home/user/automation/DemoScripts/MyLibrary.py)
    at robot.utils.importer$py._import$13(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py:154)
    at robot.utils.importer$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py)
    at robot.utils.importer$py.import_$28(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py:241)
    at robot.utils.importer$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py)
    at robot.utils.importer$py._import_class_or_module$4(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py:67)
    at robot.utils.importer$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py)
    at robot.utils.importer$py.import_class_or_module$3(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py:64)
    at robot.utils.importer$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/importer.py)
    at robot.run$py.main$3(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/run.py:367)
    at robot.run$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/run.py)
    at robot.utils.application$py._execute$10(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/application.py:87)
    at robot.utils.application$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/application.py)
    at robot.utils.application$py.execute_cli$5(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/application.py:45)
    at robot.utils.application$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/utils/application.py)
    at robot.run$py.run_cli$6(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/run.py:396)
    at robot.run$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/run.py)
    at robot.jarrunner$py._run$3(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/jarrunner.py:60)
    at robot.jarrunner$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/jarrunner.py)
    at robot.jarrunner$py.run$2(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/jarrunner.py:53)
    at robot.jarrunner$py.call_function(/Users/jmalinen/Documents/workspace/robot/tmp-jar-dir/Lib/robot/jarrunner.py)
    at org.robotframework.RobotFramework.run(RobotFramework.java:62)
    at org.robotframework.RobotFramework.main(RobotFramework.java:37)
PYTHONPATH:
  /home/user/automation/DemoScripts
  /home/user/automation/DemoScripts/robotframework-2.7.4.jar/Lib/robot/libraries
  /home/user/automation/DemoScripts/robotframework-2.7.4.jar/Lib
  /home/user/android-sdks/tools/lib/
  /home/user/automation/DemoScripts/Lib
  __classpath__
  __pyclasspath__/
  .
  /home/user/automation/DemoScripts
CLASSPATH:
  robotframework-2.7.4.jar
  /home/user/android-sdks/tools/lib/monkeyrunner.jar
  /home/user/android-sdks/tools/lib/guavalib.jar
==============================================================================

我相信与 roboframework 一起执行 monkeyrunner 测试用例是很有可能的。

有什么输入吗?

4

2 回答 2

2

@jollychang 这样做

将此添加到文件 MonkeyRunner.java

   if(chimpchat == null) {
        Map<String, String> chimp_options = new TreeMap<String, String>();
        chimp_options.put("backend", "adb");
        chimpchat = ChimpChat.getInstance(chimp_options);
        MonkeyRunner.setChimpChat(chimpchat);
    }

前:

    JythonUtils.convertDocAnnotationsForClass(MonkeyRunner.class, dict);

然后制作一个新的monkeyrunner.jar;

需要一些像这样的其他罐子: 图书馆

使用新的 monkeyrunner.jar 代替旧的。

最后:使用以下命令运行机器人:

在我的电脑上使用这个:

java -cp /Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools/lib/chimpchat.jar:/Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools/lib/ddmlib .jar:/Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools/lib/guavalib.jar:/Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools/lib/monkeyrunner .jar:/Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools/lib/sdklib.jar:/Users/komejun/Downloads/robotframework-2.7.5.jar -Dcom.android.monkeyrunner.bindir ="/Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools" -Djava.library.path="/Users/komejun/Documents/devtool/android/android-sdk-mac_x86/tools/lib" org.robotframework.RobotFramework a.txt

于 2012-11-01T07:51:09.590 回答
2

好吧,经过几天的尝试,我发现可以将MonkeyRunner脚本与Robotframework一起使用。

简而言之,您可以使用以下内容与monkeyrunner一起启动robotframework。

export cpath=$(echo libs/*.jar | tr ' ' ':')
java   -Dpython.path=$cpath -jar robotframework-2.7.4.jar robo-tests.txt

但唯一的问题是,monkeyrunner 的 main 没有被调用,因此没有初始化 ChimpChat 对象,这导致了一个空指针异常。我在 MonkeyRunner.java 中修复了这个问题,并创建了一个新的 monkeyrunner.jar。有了这个,我可以从 roboframework 运行 monkeyrunner 脚本。我将尝试创建一个分步教程并将其发布。

于 2012-10-09T21:13:50.723 回答