UIAutomator创建一个Note的实例

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

  1. package majcit.com.UIAutomatorDemo;  
  2.   
  3. import com.android.uiautomator.core.UiDevice;  
  4. import com.android.uiautomator.core.UiObject;  
  5. import com.android.uiautomator.core.UiObjectNotFoundException;  
  6. import com.android.uiautomator.core.UiScrollable;  
  7. import com.android.uiautomator.core.UiSelector;  
  8. import com.android.uiautomator.testrunner.UiAutomatorTestCase;  
  9.   
  10. public class NotePadTest extends UiAutomatorTestCase {  
  11.       
  12.      public void testDemo() throws UiObjectNotFoundException {    
  13.             UiDevice device = getUiDevice();  
  14.             device.pressHome();    
  15.             // Start Notepad  
  16.             UiObject appNotes = new UiObject(new UiSelector().text("Notes"));   
  17.             appNotes.click();    
  18.             //Sleep 3 seconds till the app get ready  
  19.             try {    
  20.                 Thread.sleep(3000);    
  21.             } catch (InterruptedException e1) {    
  22.                 // TODO Auto-generated catch block    
  23.                 e1.printStackTrace();    
  24.             }    
  25.               
  26.             //Evoke the system menu option  
  27.             device.pressMenu();  
  28.             UiObject addNote = new UiObject(new UiSelector().text("Add note"));  
  29.             addNote.click();  
  30.               
  31.             //Add a new note  
  32.             UiObject noteContent = new UiObject(new UiSelector().className("android.widget.EditText"));  
  33.             noteContent.clearTextField();  
  34.             noteContent.setText("Note 1");  
  35.             device.pressMenu();  
  36.             UiObject save = new UiObject(new UiSelector().text("Save"));  
  37.             save.click();  
  38.               
  39.             //Find out the new added note entry  
  40.             UiScrollable noteList = new UiScrollable( new UiSelector().className("android.widget.ListView"));    
  41.             //UiScrollable noteList = new UiScrollable( new UiSelector().scrollable(true));   
  42.             UiObject note = null;  
  43.             if(noteList.exists()) {  
  44.                 note = noteList.getChildByText(new UiSelector().className("android.widget.TextView"), "Note1"true);    
  45.                 //note = noteList.getChildByText(new UiSelector().text("Note1"), "Note1", true);   
  46.             }  
  47.             else {  
  48.                 note = new UiObject(new UiSelector().text("Note1"));  
  49.             }  
  50.             //assertThat(note,notNullValue());  
  51.               
  52.             note.longClick();  
  53.               
  54.             UiObject delete = new UiObject(new UiSelector().text("Delete"));  
  55.             delete.click();  
  56.                 
  57.         }    
  58.   
  59. }  

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值