MonekyRunner_Android UI Automation with Python

Read first

In Continuation to my previous post "Ui Automation on Android Basics"

Setup Environment for Android UI Automation with Python

- Download Eclipse from http://www.eclipse.org/downloads/

- Install Jython from: http://www.jython.org/downloads.html

- Install Python from: http://www.python.org/download/releases/2.7.2/

- Install pydev from: http://pydev.org/download.html, and install eclipse plugin for pydev from: http://pydev.org/updates

- Open Eclipse, Click on Window Menu => Preferences

- You should have Pydev on left side of panel, if you have installed pydev

- Expand, pydev from left panel. Click on "Interpreter - Jython"

- Click on New, give path to jython.jar, which you have installed. Click OK. It will populate the below list for libraries list.

- In Below box, click on new jar => give path to monkeyrunner.jar from AndroidSdkPath/tools/lib/monkeyrunner.jar

- Click on "Interpreter - Python" from left panel. Similarly, give path to python.exe

- Click OK, and close Preferences panel.

Create a New Pydev Project


- Create new pydev project from Eclipse.

- Use defaults, click on OK to create project

- Add a python source file in src folder of project

Sample code

?
1
2
3
4
5
6
7
8
9
10
11
12
from com.android.monkeyrunner import MonkeyDevice, MonkeyRunner, MonkeyImage, MonkeyManager
 
device = MonkeyDevice
for i in range ( 5 ):
     device = MonkeyRunner.waitForConnection( 8 )
     if device ! = None :
         print "Device found..."
         break ;
 
device.press( "KEYCODE_NOTIFICATION" , "DOWN_AND_UP" )
time.sleep( 1 )
device.press( "KEYCODE_BACK" , "DOWN_AND_UP" )

Running the code

- Open shell prompt (cmd.exe, or terminal)

- Type absolute path of monkeyrunner followed by path of python script

example: "c:\\Program Files\\Android\\android-sdk\\tools\\monkeyrunner.bat" "C:\\sample.py"

Explanation

The sample code does following:

- Wait for a Android device or emulator

- Slide down Notification bar

- sleep for 1 sec

- Press hardware button back.

Note, if you know a little python. You can do much more error checks. See references section for API usage, and more details

Run Python code from Java

This is just the extension of python code. It can give you the flexibility to extend code base to java.

You need to develop a class CommandExecutor, which can actually run a command line, and give result. I advice not to use Java's RunTime.exec(). Use Apache Exec library: http://commons.apache.org/exec/

Now, you need to wrap each UI function in a java function. Lets see above example in java form:

- Write python commands in a file in exact way as we use to write python. Take care of tabs. Lets assume filename written is "C:\\sample2.py"

- Now, execute the command like we executed above, from Java, using apache exec functions

- Wait to see the results

Note: Its very important to note here, that you actually don't need to have Python, or jython installed on Desktop. It is just required to write and compile scripts, from eclipse or any other IDE. All you need is just Android SDK



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: uiautomation python是一种基于Python语言的自动化测试工具,它可以模拟用户的操作,自动化执行GUI界面的测试用例。它可以与多种操作系统和应用程序进行交互,包括Windows、Web应用程序、Java应用程序等。使用uiautomation python可以提高测试效率,减少测试成本,是自动化测试领域的重要工具之一。 ### 回答2: UIAutomation 是一个自动化测试框架,可以用来自动化测试 iOS 应用程序。它是苹果的 Instruments 工具,用于测试 iOS 应用程序的 UI 元素。UIAutomation 具有强大的 UI 测试和自动化功能,可以模拟用户与应用程序的交互,并自动化执行测试用例。 Python 是一种非常流行的编程语言,它的简洁和易学性使其成为自动化测试领域的首选语言之一。Python 有许多库和工具用来自动化测试,其中最受欢迎的之一就是 Selenium。而 Uiautomation Python 则是基于 Python 封装的一个 UIAutomation 测试框架。 Uiautomation Python 的特点之一是其可读性非常强。Python 的语法非常简洁,易于理解,代码写起来也非常流畅。这使得编写测试用例非常直观和容易。 另一个特点是 Uiautomation Python 提供了许多工具和 API,可以让测试用例更加丰富和准确。例如,它提供了一个 UIAElement 对象来处理 UI 元素,可以非常轻松地操作包含在应用程序中的各种 UI 元素;同时,它还提供了一组高级 API,可以帮助开发者验证应用程序的各种功能。 Uiautomation Python 还提供了许多方便的功能,如测试报告、代码覆盖度分析以及自定义脚本。这些功能可以帮助开发者收集测试数据、分析测试结果和优化测试用例,以便实现高效而准确的测试过程。 总之,Uiautomation PythonPython 的简洁性和易学性与 UIAutomation 的强大功能集成在一起,为 iOS 应用程序的自动化测试提供了一个全面而优化的解决方案。 ### 回答3: UIAutomation是苹果公司提供的iOS自动化测试解决方案,它可以模拟用户通过触摸、滑动等方式的手机操作,从而实现对应用程序的自动化测试。python是一种高级编程语言,广泛应用于各种领域,包括网络编程、数据处理及自动化测试等。 在iOS自动化测试中,UIAutomation结合Python可以帮助测试人员快速构建自动化测试脚本,提高测试效率。UIAutomation提供了一系列API,可以用于查找控件、模拟用户操作、获取手机状态等。Python则可以通过调用这些API来实现自动化测试。同时,Python还提供了丰富的第三方库,在测试过程中可以使用这些库进行数据处理、图像识别、性能测试等功能,进一步拓展了UIAutomation的应用范围。 另外,Python也支持多线程和多进程处理,可以大大缩短测试时间。同时,Python还可以与Jenkins等持续集成工具结合使用,实现自动化测试的持续集成,提高软件质量。 总体来说,UIAutomationPython的结合,可以对iOS应用程序进行全面的自动化测试,提高测试效率和软件质量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值