机器人问题
我刚刚开始使用robotium。演示可以毫无问题地运行,但是当我使用 EditText
和 Button
编写第一个测试脚本时,出现了问题。我的环境是android 2.1,脚本非常简单,只需输入用户名和密码,然后单击sumbit按钮即可登录。
脚本如下:
package com.tpc.test;
import com.tpc.login.Login;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;
public class LoginTest extends ActivityInstrumentationTestCase2<Login>{
private Solo solo;
public LoginTest() {
super("com.tpc", Login.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Smoke
public void testApp() throws Exception {
String appName = solo.getCurrentActivity().getClass().getSimpleName();
System.out.println(appName);
solo.getButton(0).getClass().getSimpleName();
solo.assertCurrentActivity("Expected login activity", appName);
System.out.println(solo.getButton(0).getText());//can get the text of button
solo.enterText(0, "name"); //input name to the 1st EditText is OK
solo.enterText(1, "psw"); // Actually inout psw after name to the 1st EditText
solo.clickOnButton(0); //Expect click the 1st button.Actually click the 1st EditText
//assert of sample, not been modified
boolean expected = true;
boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
assertEquals("Note 1 and/or Note 2 are not found", false, actual);
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
一个问题是第一个EditText
中同时填写了name和psw,另一个是solo.clickOnButton(0);
点击第一个EditText
,而不是第一个 Button
。我也尝试使用Button
的文本名称,但结果是一样的。似乎所有的操作都放在第一个EditText
中。我想知道是什么问题有什么建议吗?谢谢
I just start to use robotium. The demo can be run without any problem, but when I wrote first test script by using EditText
and Button
, problems occured. My environment is android 2.1 and the script is quite simple, just input username and psw, then click sumbit button to login.
The script is as follows:
package com.tpc.test;
import com.tpc.login.Login;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.Smoke;
public class LoginTest extends ActivityInstrumentationTestCase2<Login>{
private Solo solo;
public LoginTest() {
super("com.tpc", Login.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Smoke
public void testApp() throws Exception {
String appName = solo.getCurrentActivity().getClass().getSimpleName();
System.out.println(appName);
solo.getButton(0).getClass().getSimpleName();
solo.assertCurrentActivity("Expected login activity", appName);
System.out.println(solo.getButton(0).getText());//can get the text of button
solo.enterText(0, "name"); //input name to the 1st EditText is OK
solo.enterText(1, "psw"); // Actually inout psw after name to the 1st EditText
solo.clickOnButton(0); //Expect click the 1st button.Actually click the 1st EditText
//assert of sample, not been modified
boolean expected = true;
boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
assertEquals("Note 1 and/or Note 2 are not found", false, actual);
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
}
One problem is both name and psw is filled in the first EditText
,the other is solo.clickOnButton(0);
click the first EditText
, NOT the first Button
. I also tried to use the text name of the Button
, but the result was the same. It seems all the operations been put to the first EditText
. I wanna what's the problem. Any suggestion?thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我查看了您想要测试的应用程序,问题是您没有声明它支持高密度屏幕。当您在高密度模拟器/设备上使用 Robotium 时,这会给 Robotium 带来问题。
您需要在 AndroidManifest.xml 中添加以下标记:
如果您将该标记添加到 AndroidManifest.xml 中,那么它将起作用。
I have had a look at the application that you want to test and the problem is that you do not state that it supports high density screens. That gives Robotium problems as you are using it on a high density emulator/device.
You need to add the following tag in the AndroidManifest.xml:
<supports-screens android:anyDensity="true"/>
If you add that tag to your AndroidManifest.xml then it will work.
希望您将输入文本作为数组.. 0 和 1..
但希望您没有初始化数组
希望如果您初始化数组列表,它会起作用。尝试一下。
Hope you are taking the enter text as a array.. 0 and 1..
But hope you didn't initialize the array
Hope it will work if you initialize the arraylist. Have a try.
您可以尝试将此标记添加到 AndroidManifest.xml 中:
其中 7 表示 Android 2.1。如果这不起作用,请将其发布到 Robotium 开发人员页面上,我将查看它。
http://groups.google.com/group/robotium-developers
此致
雷纳斯
You could try to add this tag to your AndroidManifest.xml:
<uses-sdk android:targetSdkVersion="7"/>
where 7 means Android 2.1.If that does not work then please post this on the robotium developers page and I will have a look at it.
http://groups.google.com/group/robotium-developers
Sincerely,
Renas
我也遇到了这个问题,但我找不到 Robotium 的解决方案。然后我转向 SDK 提供的 Android 仪器。我所做的事情如下所述。这对我来说没有任何问题。这里是..
首先为按钮定义一个私有变量作为成员变量
然后在setup方法中获取按钮实例。
然后在测试方法的 UI 线程中调用按钮单击,如下所述。
就是这样..现在您可以使用其他 Robotium 功能测试您的按钮。
I also had this issue and i couldn’t find a solution with robotium. Then i move to the android instrumentation provided with the SDK. What i have done is mentioned below. This worked without any issues for me. Here it is ..
First define a private variable for the button as a member variable
Then get the button instance with in the setup method.
Then call the button click with in the UI thread in the test method as mentioned below.
That’s it .. Now you can test your button with other Robotium features.