UIAutomator创建一个Note的实例

紧接之前的创建一个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();
	          
	    }  

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值