需求分析
找到主页界面中的5个控件按钮 挨个点击
上代码
package cn.vlang.test01;
import android.os.RemoteException;
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 Uidevice extends UiAutomatorTestCase{
public void testDemo() throws UiObjectNotFoundException, RemoteException{
getUiDevice().pressMenu();
getUiDevice().pressBack();
UiObject bn = new UiObject(new UiSelector().text("Phone"));
bn.click();
getUiDevice().pressBack();
bn = new UiObject(new UiSelector().text("Contacts"));
bn.click();
getUiDevice().pressBack();
bn = new UiObject(new UiSelector().text("Messaging"));
bn.click();
getUiDevice().pressBack();
bn = new UiObject(new UiSelector().text("Internet"));
bn.click();
getUiDevice().pressBack();
bn = new UiObject(new UiSelector().text("Apps"));
bn.click();
getUiDevice().pressBack();
}
}
需求分析2
点开浏览器 输入www.baidu.com 之后访问
package cn.vlang.test01;
import android.os.RemoteException;
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 Uidevice extends UiAutomatorTestCase{
public void testDemo() throws UiObjectNotFoundException, RemoteException{
getUiDevice().pressMenu();
getUiDevice().pressBack();
UiObject bn = new UiObject(new UiSelector().text("Internet"));
bn.click();
bn = new UiObject(new UiSelector().className("android.widget.EditText"));
bn.setText("www.baidu.com");
getUiDevice().pressEnter();
}
}