• Robotuim自动化步骤梳理


    一、简介 

    robotium自动化测试过程 测试case以apk的形式在运行在安装待测应用的设备上,以instrument注入的方式调用待测apk

     待测apk包名(com.calculator)  测试case apk中 AndroidMainFest.xml

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.calculator" />

    二、附上一份case

      

    /**
    * @author BlackStone
    *
    */
    public class MainTest extends ActivityInstrumentationTestCase2{

    /**
    * @param activityClass
    */


    public Solo solo;
    public Activity activity;
    private static Class launchActivityClass;

    private static String mainActivity="com.calculator.Main";
    //private static String packageName="com.calculator";

    static{
    try {
    launchActivityClass=Class.forName(mainActivity);
    } catch (ClassNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    @SuppressWarnings("unchecked")
    public MainTest(){
    super(launchActivityClass);
    // TODO Auto-generated constructor stub
    }


    /**
    * @ClassName: MainTest
    * @Description: TODO(这里用一句话描述这个类的作用)
    * @date 2017年8月9日 下午12:49:00
    *
    */

    /* (non-Javadoc)
    * @see android.test.ActivityInstrumentationTestCase2#setUp()
    */
    @Before
    protected void setUp() throws Exception {
    super.setUp();
    this.activity=this.getActivity();
    this.solo = new Solo(getInstrumentation(), getActivity());
    }

    /* (non-Javadoc)
    * @see android.test.ActivityInstrumentationTestCase2#tearDown()
    */

    @Test
    public void testDisplayWhiteBox() {

    float vFirstNumber = 10;

    float vSecondNumber = 10;

    float vResult = vFirstNumber * vSecondNumber;

    EditText vFirstEditText = (EditText) solo.getView("com.calculator:id/EditText01");
    solo.clearEditText(vFirstEditText);

    solo.enterText(vFirstEditText, String.valueOf(vFirstNumber));

    // AccessSecondvalue(edit-filed)andputtingSecondNumbervalueinit

    EditText vSecondEditText = (EditText) solo.getView("com.calculator:id/EditText02");

    solo.clearEditText(vSecondEditText);

    solo.enterText(vSecondEditText, String.valueOf(vSecondNumber));

    // ClickonMultiplybutton

    solo.clickOnButton("Multiply");

    assertTrue(solo.searchText(String.valueOf(vResult)));

    TextView outputField = (TextView) solo.getView("com.calculator:id/TextView01");

    // Assert to verify result with visible value

    assertEquals(String.valueOf(vResult), outputField.getText().toString());

    }

    @After
    protected void tearDown() throws Exception {
    solo.finishOpenedActivities();
    super.tearDown();

    }


    }

    三、打包用例工程步骤

     

    一、打包资源文件 生成R.java

    D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/build-tools/19.0.1/aapt.exe p -m -J C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/gen -M C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/AndroidManifest.xml -S C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/res -I D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/platforms/android-19/android.jar


    D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/build-tools/19.0.1/aapt.exe p -m -J C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/gen -MC:/Users/ThinkPad/Desktop/AndroidCalculatorTest/AndroidManifest.xml -S C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/res -I D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/platforms/android-19/android.jar


    二、处理AIDL文件

    javac -encoding utf-8 -target 1.7 -bootclasspath D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/platforms/android-19/android.jar;D:/apache-maven-3.2.3/repo/junit/junit/4.12/junit-4.12.jar;D:/workspace/AndroidCalculatorTest/libs/robotium-solo-5.6.3.jar -d C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/bin C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/src/com/calculator/test/*.java C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/gen/com/calculator/test/R.java

    三、编译java文件生成 .class

    D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/build-tools/19.0.1/dx.bat --dex --output C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/bin/classes.dex C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/bin


    四 。打包

    aapt package -f -A
    C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/assets -S C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/res -I D:/ADT/adt-bundle-windows-x86_64-20140702/sdk/platforms/android-19/android.jar C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/AndroidManifest.xml -F bin/test


    jarsigner -verbose -keystore C:/Users/ThinkPad/Desktop/HHH/me.keystore -storepass 123456 -keypass 123456 -signedjar C:/Users/ThinkPad/Desktop/HHH/AndroidCalculator-signed-me.apk C:/Users/ThinkPad/Desktop/HHH/AndroidCalculator.apk me.keystore

    jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore C:/Users/ThinkPad/Desktop/HHH/debug.keystore -storepass android -keypass android -signedjar C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/bin/AndroidCalculatorTest-signed.apk C:/Users/ThinkPad/Desktop/AndroidCalculatorTest/bin/AndroidCalculatorTest.apk androiddebugkey

    jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore C:/Users/ThinkPad/Desktop/HHH/debug.keystore -storepass android -keypass android -signedjar C:/Users/ThinkPad/Desktop/HHH/AndroidCalculator-resigned.apk C:/Users/ThinkPad/Desktop/HHH/AndroidCalculator-signed-me.apk androiddebugkey

    1.去除签名
    其实很简单,用WinRAR打开apk,找到META-INF文件夹,删除MANIFEST.MF之外的所有其他文件即可


    adb shell pm list instrumentation
    adb shell am instrument -w com.calculator.test/android.test.InstrumentationTestRunner

  • 相关阅读:
    shell读取文件不改变文本格式
    lua 的 os.date os.time
    gerrit 操作
    docker 的 镜像生成系列
    Windows 跟 Linux 文件共享:Samba 设置
    viscode 使用 格式的配置
    python pip 升级 或者换源
    centos 的系统管理命令 service systemctl
    Linux 的 netstat 命令
    MVC 、MTV 模式
  • 原文地址:https://www.cnblogs.com/heishi/p/8205134.html
Copyright © 2020-2023  润新知