移动测试基础 uiautomator 测试脚本学习

55hhy · 2014年03月19日 · 最后由 superman 回复于 2015年12月17日 · 1400 次阅读

最近在学习
http://developer.android.com/tools/testing/testing_ui.html
测试软件:盛大 有你
我的测试代码如下:
package com.snda.youni;

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 OpenYouni extends UiAutomatorTestCase{
public void OpenYouniFirst() throws UiObjectNotFoundException {
getUiDevice().pressHome();

UiObject youniBtn = new UiObject(new UiSelector().index(3) .className(android.view.View.class.getName()));
youniBtn.clickAndWaitForNewWindow();

UiObject socialNet = new UiObject(new UiSelector().text("社交圈"));
socialNet.click();

}
}
执行测试的结果是:
haohuiyan@haohuiyan:~/Documents/workspace/TestYouni/bin$adb shell uiautomator runtest TestYouni.jar -c com.snda.youni.OpenYouni
INSTRUMENTATION_STATUS: stream=
Test results for UiAutomatorTestRunner=
Time: 0.0

OK (0 tests)

INSTRUMENTATION_STATUS_CODE: -1
感觉完全没有执行,我就觉得是我的代码的问题,有你这个软件里面没有 android:hint 也没有 android:contentDescription,我就用了 index,好像不管用。求教

共收到 6 条回复 时间 点赞

@55hhy 好像 Uiautomator 的测试 case 名称要以 test 开头,把 OpenYouni 改成 testOpenYouni 试试

要有具体的测试方法~

方法名要加 test 吧。testOpenYouniFirst()

uiautomator 好像不支持中文 text,所以换成英文试试。

没看懂,这 app 是原生的还是混合的啊。 如果是原生的, 你可以打印下你定位的对象的具体属性

Answer myself:
UiObject youniBtn = new UiObject(new UiSelector().index(3).className(android.view.View.class.getName()));这一步不能定位到主页上的有你 application,所有后来我通过 click(int int) 的方式实现的

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册