UIAutomator创建一个Note的实例

发布时间:2020-07-16 11:29:49 作者:zhukev
来源:网络 阅读:217

紧接之前的创建一个Note的Appium和Robotium的实例,这里给出实现同样功能的UIAutomator的实例如下:

package majcit.com.UIAutomatorDemo;  import com.android.uiautomator.core.UiDevice; import com.android.uiautomator.core.UiObject; import com.android.uiautomator.core.UiObjectNotFoundException; import com.android.uiautomator.core.UiScrollable; import com.android.uiautomator.core.UiSelector; import com.android.uiautomator.testrunner.UiAutomatorTestCase;  public class NotePadTest extends UiAutomatorTestCase { 	 	 public void testDemo() throws UiObjectNotFoundException {   	        UiDevice device = getUiDevice(); 	        device.pressHome();   	        // Start Notepad 	        UiObject appNotes = new UiObject(new UiSelector().text("Notes"));  	        appNotes.click();   	        //Sleep 3 seconds till the app get ready 	        try {   	            Thread.sleep(3000);   	        } catch (InterruptedException e1) {   	            // TODO Auto-generated catch block   	            e1.printStackTrace();   	        }   	         	        //Evoke the system menu option 	        device.pressMenu(); 	        UiObject addNote = new UiObject(new UiSelector().text("Add note")); 	        addNote.click(); 	         	        //Add a new note 	        UiObject noteContent = new UiObject(new UiSelector().className("android.widget.EditText")); 	        noteContent.clearTextField(); 	        noteContent.setText("Note 1"); 	        device.pressMenu(); 	        UiObject save = new UiObject(new UiSelector().text("Save")); 	        save.click(); 	         	        //Find out the new added note entry 	        UiScrollable noteList = new UiScrollable( new UiSelector().className("android.widget.ListView"));   	        //UiScrollable noteList = new UiScrollable( new UiSelector().scrollable(true));  	        UiObject note = null; 	        if(noteList.exists()) { 	        	note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1", true);   	        	//note = noteList.getChildByText(new UiSelector().text("Note1"), "Note1", true);  	        } 	        else { 	        	note = new UiObject(new UiSelector().text("Note1")); 	        } 	        //assertThat(note,notNullValue()); 	         	        note.longClick(); 	         	        UiObject delete = new UiObject(new UiSelector().text("Delete")); 	        delete.click(); 	           	    }    } 


推荐阅读:
  1. uiautomator 编译运行步骤
  2. SDK Instrumentation创建一个Note的实例

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

note 创建 uiautomator

上一篇:php的魔法方式都有什么

下一篇:解决postgresql的权限不够的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》