移动测试基础 robotium 测试工程 找不到 “登陆” 按钮,怎么办

张伟 · 2014年05月06日 · 最后由 木月 回复于 2015年11月13日 · 1944 次阅读

运行结果:
junit.framework.AssertionFailedError: Button with text: '登陆' is not found!
at com.robotium.solo.Clicker.clickOn(Clicker.java:471)
at com.robotium.solo.Solo.clickOnButton(Solo.java:888)
at com.chinamobile.iot.smarthome.test.Firstone.testLogin(Firstone.java:40)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:529)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1448)

代码如下:
public class Firstone extends ActivityInstrumentationTestCase2 {

private Solo solo;

public Firstone() {
super("com.chinamobile.iot.smarthome", WelcomeActivity.class);

}

public void setUp() throws Exception {

solo = new Solo(getInstrumentation(), getActivity());
}

public void tearDown() throws Exception {
.
solo.finishOpenedActivities();
}

public void testLogin() throws Exception {

solo.clickOnButton("登陆");

logcat:
05-06 08:56:30.867: E/dalvikvm(23781): Could not find class '[Landroid.view.MotionEvent$PointerProperties;', referenced from method com.robotium.solo.Zoomer.generateZoomGesture

共收到 9 条回复 时间 点赞

用 id 去做操作,text 寻找是不一定找得到的

登陆写错了吧,一般是登录

#2 楼 @shixue33 额 ,是在这些打错了,工程里没有错,是登录

#1 楼 @monkey 用 ID 也试了 ,报找不到这个 ID,是不是 robotium 只支持 junit4

#3 楼 @azdwa solo.getCurrentViews 用 Button 筛选一下,你试一下,看看那个按钮是哪个

#4 楼 @azdwa 其实 robotium 是支持 juint3.不支持 4 的。。= =。。

LZ 的方法不是很好,使用 Text 去识别控件本身失败率就很高。原因可能有:
1.“登录” 两个字之间有空格;
2.“登录” 看上去是文字,实际上是图片;
3.这个控件并不是 button,而是 imageView;

建议使用 ClickOnView

#7 楼 @joshua 嗯,谢谢,后面发现还是 ClickOnView 比较好用

使用 id 的方法比较靠谱

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