机器人问题

发布于 2024-09-15 03:55:00 字数 2100 浏览 13 评论 0原文

我刚刚开始使用robotium。演示可以毫无问题地运行,但是当我使用 EditTextButton 编写第一个测试脚本时,出现了问题。我的环境是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

他不在意 2024-09-22 03:55:00

我查看了您想要测试的应用程序,问题是您没有声明它支持高密度屏幕。当您在高密度模拟器/设备上使用 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.

御守 2024-09-22 03:55:00

希望您将输入文本作为数组.. 0 和 1..

但希望您没有初始化数组

import java.util.Arraylist;

希望如果您初始化数组列表,它会起作用。尝试一下。

Hope you are taking the enter text as a array.. 0 and 1..

But hope you didn't initialize the array

import java.util.Arraylist;

Hope it will work if you initialize the arraylist. Have a try.

荒路情人 2024-09-22 03:55:00

您可以尝试将此标记添加到 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

围归者 2024-09-22 03:55:00

我也遇到了这个问题,但我找不到 Robotium 的解决方案。然后我转向 SDK 提供的 Android 仪器。我所做的事情如下所述。这对我来说没有任何问题。这里是..

首先为按钮定义一个私有变量作为成员变量

private Button msButton;  

然后在setup方法中获取按钮实例。

mButton = (Button) solo.getCurrentActivity().findViewById(
com.marakana.android.simple_intent.R.id.sendButton); 

然后在测试方法的 UI 线程中调用按钮单击,如下所述。

//Test button method

public void testButtonClick() {

//Get the current activity and request to run onUI thread
solo.getCurrentActivity().runOnUiThread(new Runnable() {

public void run() { 

//Request focus for the button
mButton.requestFocus();
}
});

//Send the button click event
this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);

}

就是这样..现在您可以使用其他 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

private Button msButton;  

Then get the button instance with in the setup method.

mButton = (Button) solo.getCurrentActivity().findViewById(
com.marakana.android.simple_intent.R.id.sendButton); 

Then call the button click with in the UI thread in the test method as mentioned below.

//Test button method

public void testButtonClick() {

//Get the current activity and request to run onUI thread
solo.getCurrentActivity().runOnUiThread(new Runnable() {

public void run() { 

//Request focus for the button
mButton.requestFocus();
}
});

//Send the button click event
this.sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);

}

That’s it .. Now you can test your button with other Robotium features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文