zoukankan      html  css  js  c++  java
  • Robotium框架(只有apk包)

    学习Robotium一段时间了,整理了robotium的框架,包含如何通过控件的ID识别和控制控件,推荐阅读这篇文章

     1 package com.xxxxx.xxxx;
     2
    3
    4 import com.jayway.android.robotium.solo.Solo; 5
    6
    import android.R.string; 7 import android.test.ActivityInstrumentationTestCase2; 8 import android.view.View; 9 10 @SuppressWarnings({ "unchecked", "rawtypes" }) 11 public class TestMain extends ActivityInstrumentationTestCase2 { 12 public TestMain(Class activityClass) { 13 super(activityClass); 14 // TODO Auto-generated constructor stub 15 } 16 17 private static final String TARGET_PACKAGE_ID = "com.xxxxx"; 18 private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = 19 "com.xxxxx.xx.xxxxxxxxxxxxx"; 20 21 private static Class<?> launcherActivityClass; 22 static { 23 try { 24 launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME); 25 } catch (ClassNotFoundException e) { 26 throw new RuntimeException(e); 27 } 28 } 29 30 public TestMain() throws ClassNotFoundException{ 31 super(TARGET_PACKAGE_ID, launcherActivityClass); 32 } 33 34 private Solo solo; 35 36 @Override 37 protected void setUp() throws Exception { 38 solo = new Solo(getInstrumentation(), getActivity()); 39 } 40 41 @Override 42 public void tearDown() throws Exception { 43 try{ 44 solo.finalize(); 45 } catch(Throwable e) { 46 e.printStackTrace(); 47 } 48 getActivity().finish(); 49 super.tearDown(); 50 } 51 52 53 //封装好的通过id查找控件的方法,方法摘取自http://blog.sina.com.cn/s/blog_6abda9bc01015zoc.html 54 55 /*private int clickCtrlById(String s, int t ){ 56 int ctrl; 57 View v; 58 59 if( s == ""){ 60 return -1; 61 } 62 ctrl = solo.getCurrentActivity().getResources().getIdentifier(s, "id", TARGET_PACKAGE_ID); 63 64 v = solo.getView(ctrl); 65 solo.clickOnView(v); 66 solo.sleep(t); 67 return 0; 68 }*/ 69 70 71 public void testCase1(){ 72 solo.pressMenuItem(0); 73 solo.goBack(); 74 75 //使用封装好的方法 76 //clickCtrlById("btn_button_01", 400); 77 78 //直接写 79 solo.clickOnView( 80 solo.getView( 81 solo.getCurrentActivity().getResources().getIdentifier( 82 "btn_button_01", "id", TARGET_PACKAGE_ID ))); 83 84 } 85 86 }
  • 相关阅读:
    c#参数传递几点小结
    c#线程初探(二)
    c#线程初探(一)
    c#:浅克隆和深克隆,序列化和反序列化
    c#冒泡、快速、选择和插入排序算法的项目应用
    c#运算符几点小结
    文件操作(无代码)
    不仅仅C#缺点(永远未完)
    《道德经》程序员版第五章
    《道德经》程序员版第四章
  • 原文地址:https://www.cnblogs.com/vincentvan/p/2853788.html
Copyright © 2011-2022 走看看