austgl / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

help~ My apk has two activity when it starts. but when it starts B activity,the Process has died. 选项 #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
My apk has two activity when it starts. the A activity and B acticity. 
when it starts, the A activity work(it is the welcome page).after 
5S ,the B activity work. 
But,i use robotium,when it starts B  activity,the Process has died. 

A activity: Main Activity
B activity: MyStockActivity

LOGCAT: 
12-22 14:29:43.870: INFO/ActivityManager(563): Starting activity: 
Intent { comp={com.test.in/com.test.in.MyStock.MyStockActivity} } 
12-22 14:29:43.889: INFO/Process(1474): Sending signal. PID: 1474 SIG: 
9 
12-22 14:29:43.909: INFO/ActivityManager(563): Process com.test.in 
(pid 1474) has died. 
12-22 14:29:43.909: INFO/WindowManager(563): WIN DEATH: 
Window{435d8978 com.test.in/com.test.in.MainActivity paused=true} 
12-22 14:29:43.949: WARN/ActivityManager(563): Crash of app 
com.test.in running instrumentation ComponentInfo{com.test.test/ 
android.test.InstrumentationTestRunner} 
12-22 14:29:43.960: DEBUG/ActivityManager(563): Uninstalling process 
ccom.test.in 
12-22 14:29:43.960: DEBUG/ActivityManager(563):   Force finishing 
activity com.test.in /.MyStock.MyStockActivity 

AndroidManifest.xml:
  <instrumentation android:targetPackage="com.test.in" 
android:name="android.test.InstrumentationTestRunner" />

My code:

import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
@SuppressWarnings("rawtypes")
public class InvestWinnerTest  extends ActivityInstrumentationTestCase2{
    private static final String TARGET_PACKAGE_ID   ="com.hundsun.invw";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.test.in.MainActivity";

    private static  Class<?>launcherActivityClass;

    static{
        try {
        launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        }catch(ClassNotFoundException e){
        throw new RuntimeException(e);
        }
    }

    @SuppressWarnings("unchecked")
    public  InvestWinnerTest()  throws Exception{
            super(TARGET_PACKAGE_ID, launcherActivityClass);
    }

    private Solo solo;

    protected void  setUp() throws Exception{ 
         solo = new Solo(getInstrumentation(), getActivity());
    } 

     public void testAddStock() throws Exception {
         String appName = solo.getCurrentActivity().getClass().getSimpleName();
         System.out.println(appName);

         solo.sleep(5000);
         solo.waitForActivity("MyStockActivity", 10000);  
         System.out.println("waitForActivity");
         solo.assertCurrentActivity("Expected MyStock activity", "MyStockActivity");
         System.out.println("MyStockActivity");

         solo.sendKey(Solo.ENTER);
         System.out.println("关闭键盘");
         solo.clickOnButton(48);         
         solo.assertCurrentActivity("Expected EditMyStock activity", "EditMyStockActivity"); //Assert that NoteEditor activity is opened
         System.out.println("进入设置自选");

         solo.clickOnButton(47);
         solo.enterText(0, "600160"); //In text field 0, add Note 1
         solo.clickOnButton(52);
         solo.goBack(); //Go back
         solo.goBackToActivity("MyStockActivity"); //Go back to first activity named "NotesList"
         boolean expected = true;
         boolean actual = solo.searchText("巨化股份");
         assertEquals("添加自选股失败", expected, actual);
     }

        public void tearDown() throws Exception{
            try{
                solo.finalize();
            }
            catch(Throwable e){
                e.printStackTrace();
            }

            getActivity().finish();
            super.tearDown();
        }

}

Original issue reported on code.google.com by chenmeng...@gmail.com on 22 Dec 2010 at 7:06

GoogleCodeExporter commented 9 years ago
Were in the test case are you when the process dies? What line? There seems to 
be something wrong with your test project. The crash is not in Robotium.

Original comment by renasr...@gmail.com on 22 Dec 2010 at 1:06

GoogleCodeExporter commented 9 years ago
What crashes is the instrumentationtestrunner which has nothing to do with 
Robotium. I would recommend you to reinstall the SDK. 

Original comment by renasr...@gmail.com on 22 Dec 2010 at 7:13

GoogleCodeExporter commented 9 years ago
i have reinstall the SDK many times. it doesnot work . i think it is because i 
have 2 activities when the apk starts.

Original comment by chenmeng...@gmail.com on 27 Dec 2010 at 1:51

GoogleCodeExporter commented 9 years ago
Many people have 2 activities when the apk starts. That is not something 
strange.

Original comment by renasr...@gmail.com on 28 Dec 2010 at 10:36

GoogleCodeExporter commented 9 years ago
Hi Rensar,

I seem to have similar problem. My App has a Page (Activity A) with a button on 
it. On clicking that button, a webpage (Activity B) is launched. Once the 
Webpage is launched, the Test Case halts. It doesn't do anything. I have tried 
solo.goBack and also solo.goBackToActivity(ActivityA) to go back t the App 
(Activity A). Neither of them works. When I tried the latter, the error message 
I got was 'ActivityA no longer exists' or something like this. When the webpage 
is launched (Activity B), the App (Activity A) is closing. Once the Test case 
halts on the web page, if I manually press the 'back' button on the Emulator, I 
don't see my App anymore. I think this happens only when I am attempting to 
automate the Test using Robotium. When I run the following Steps on my App 
manually using the Emulator, the behaviour is different.
(1) Launch the App, and go to the Page that has the button.
(2) Press the button, and the webpage is launched.
(3) Press the 'back' button on the Emulator.
(4) The App is still there. It's not closed. 

Please let me know if there's a way to get around this, or if I'm doing 
anything wrong.

Many Thanks,
V.

Original comment by robotium...@gmail.com on 1 Mar 2011 at 4:20

GoogleCodeExporter commented 9 years ago
i have faced the same problem as above.

Is there a way where we can get the robotium test case to run even after the 
original activity has closed?

Thanks 
Dinesh

Original comment by xperiaofdinesh@gmail.com on 23 Jun 2011 at 10:14