appUi测试初探

环境搭建:

1.配置java环境

2.配置sdk环境

3.配置ant环境

4.准备eclipse

 

常用命令:

1.当前链接设备: adb devices

2.查看adb服务所需端口:adb nodaemon server

3.查看某端口情况:netstat -ano | findstr “5037”

 

UiAutomator注意点:

1.新建项目从sdk - platforms中倒入“android.jar” 和 “uiautomator.jar”包

2.使用Junit执行

3.每个TestCase命名以test开始:

package com.ln.test;                                    ----------------自己命名包,方便后面调用。
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

 

public class AutoTestDemo extends UiAutomatorTestCase {
 public void testnewTestCase() throws UiObjectNotFoundException{     ----------------每条测试用例以test开头
   UiObject username = new UiObject(new UiSelector().resourceId("com.insthub.ezudao:id/signin_mobile_phone"));
      username.setText("13260227650");
      UiObject pwd = new UiObject(
                 new UiSelector().resourceId("com.insthub.ezudao:id/signin_password"));
         pwd.setText("123456");
         UiObject submit = new UiObject(
                 new UiSelector().resourceId("com.insthub.ezudao:id/signin_signin"));
         submit.click();
         
 }

}

 

对象值使用sdk-tools中的uiautomatorviewer查看。

 

4.生成 build文件:android create uitest-project -n <name> -t <android-sdk-ID> -p <path>

name:build文件中的name,即生成的jar的name。

android-sdk-id:使用 android list 查看当前id

path:eclipse的workspace目录

 

5.修改build.xml,将default中的help改为build。

 

6.生成jar包:ant -buildfile "path"

path:同上

 

7.将jar包push到设备中:adb push "path\bin\Demo.jar"  /data/local/tmp/  

path :同上

 

8.执行测试用例:adb shell uiautomator runtest Demo.jar --nohup -c com.hj.autotest.UiAutomatorTestCase #testnewTestCase    ------------一次只能执行一条

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值