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();
}
}
}