views:

343

answers:

3

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

A: 

I am facing the same problem.. Quintin got any hint..

jadav
Have u resolved this problem?
Joe
You could try to add this tag to the AndroidManifest.xml of your application:<supports-screens android:anyDensity="true"/>
Joe
+1  A: 

Hi,

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

Renas
Dear Renas,Sorry, I cannot open this link
Joe
+1  A: 

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.

Renas
Now the problem is solved.Thanks a lot.
Joe