android 谷歌官方案例,android中google提供的官方uiautomator进行ui自动化测试案例例子...

import java.io.IOException;

import com.android.uiautomator.core.UiCollection;

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 TestOne extends UiAutomatorTestCase {

public void testDemo() throws UiObjectNotFoundException {

//启动应用

try {

Process pro = Runtime.getRuntime().exec("am start -n com.example.test/com.example.test.Activity ");

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//点击联系人

UiObject uob = new UiObject(new UiSelector().text("联系人")) ;

uob.click();

//搜索联系人,输入文字“S”

System.out.println(" the edit is a ");

UiObject edit = new UiObject(new UiSelector().text("搜索联系人")) ;

System.out.println(" the edit is "+edit);

edit.setText("s");

//选取好友

System.out.println(" the friends is a ");

UiObject friends = new UiObject(new UiSelector().text("saloris")) ;

System.out.println(" the friends is "+edit);

friends.setText("s");

//点击添加“+”号

UiDevice ud = UiDevice.getInstance();

System.out.println(" the devi is "+ud);

ud.click(140, 1140);

//相册

UiObject photo = new UiObject(new UiSelector().text("相册")) ;

photo.click();

//图集

UiDevice tu = UiDevice.getInstance();

System.out.println(" the tu div is "+ud);

tu.click(562, 303);

//打开图集

System.out.println(" the cancle is a ");

UiObject cancle = new UiObject(new UiSelector().text("取消")) ;

System.out.println(" the cancle is "+cancle);

if(cancle.exists()){

//点击图片

UiDevice tu2 = UiDevice.getInstance();

System.out.println(" the tu div is "+ud);

tu.click(383, 552);

//点击确定

System.out.println(" the ok is a ");

UiObject ok = new UiObject(new UiSelector().text("完成")) ;

System.out.println(" the ok is "+ok);

ok.click();

}

}

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值