English 中文(简体)
机器人问题
原标题:problem of robotium

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();
    } 
}

一个问题在第一个<代码>EditText上填满,另一个问题是solo.clickOnButton(0); 点击第一个EditText,NOT 第一个Button/code>。 我还尝试使用<条码>Button的文字名称,但结果相同。 看来所有业务都放在第1条<代码>EditText上。 我 w住这个问题。 任何建议? 感谢

问题回答

我看着你想要测试的申请,问题是你没有说它支持高密度屏幕。 这带来了机器人的问题,因为你正在使用高密度 em子/dev。

你们需要在安伯里夫斯特添加以下标签:

<supports- Screens android:anyDensity=“true”/>

如果你在安妮斯·曼尼费斯上添加这一标签,它就会发挥作用。

希望你将进入案文作为阵列。

但是,希望你们能够先入住阵列。

import java.util.Arraylist;

如果你开始编制该名单,希望会发挥作用。 进行审判。

您可以尝试在你身上添加这一方面。 AndersManifest.xml:

<uses-sdk android:targetSdkVersion=“7”/> where 7 means Degrading 2.1.

如果不可行,请在机器人网页上张贴这一信息,我将对此进行仔细研究。

http://groups.google.com/group/robotium-developers” rel=“nofollow noreferer” http://groups.google.com/group/robotium-developers

Sincerely, Renas

我也曾有过这个问题,而且我无法找到一种解决办法。 然后移至向SDK提供的roid仪器。 下文提到了我所做的工作。 这对我没有任何问题。 这里是。

第一,将纽伦的私人变量界定为成员变量

private Button msButton;  

然后,在安装方法中采用纽扣。

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

然后,将 but子点击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);

}

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





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签