UiAutomator初识-在android上进行UiAutomator 测试基本步骤

1.首先创建一个文件夹(如laiwan),命令行切换到laiwa目录下。

2.Android createuitest-project -p . -t android-16。

3.在eclipse中新增java项目(如laiWanTest),将laiwa文件夹下的文件复制粘贴到Eclipse的laiWanTest项目中。

4. 引入sdk\platforms\android-16下的android 及uiautomator jar包;add library-JUnit4。

5.写一段简单的点击"所有应用”试验一下

package com.laiwan.test;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class laiwanTest extends UiAutomatorTestCase {
	public void testClickApps(){
		UiDevice device =this.getUiDevice();
		device.pressHome();
		UiObject textView =new UiObject(new UiSelector().description("Apps"));		
		
		try {
			textView.click();
		} catch (UiObjectNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

6.在命令行切换到项目目录(如我的:E:\aworkspace\laiWanTest)运行ant build,在bin目录下生产一个.jar文件。

7.将这个.Jar文件push到手机的/data/local/tmp下。

adb  push  laiwan.jar/data/local/tmp

8.运行测试。

adb shell uiautomatorruntest laiwan.jar  -c com.laiwan.test.laiwanTest


OK 看到模拟器上点击了一下中间的按钮,进入到所有应用。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值