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 }
  • 相关阅读:
    OpenFace 调试记录
    Q-Q图和P-P图
    混沌理论(Chaos theory)和非线性系统
    vxlan 协议
    浮动IP地址(Float IP)与 ARP欺骗技术
    Huawei® ENSP & VRP CheatSheet
    多分类问题中查全率和查准率的理解
    urllib 报错 IOError: [Errno socket error] TLS/SSL connection has been closed (EOF) (_ssl.c:590)
    小世界网络
    表型数据(Phenotype Data)基本概念
  • 原文地址:https://www.cnblogs.com/vincentvan/p/2853788.html
Copyright © 2011-2022 走看看