How to check my current activity after intent with Robotium

I have a tedious problem with Robotium. Usually, while I'm testing Robotium, if it went to SecondActivity by clicking the button in FirstActivity, Robotium can check that SecondActivity with the assertCurrentActivity () method.

For example, an activity opens, the "A" button is pressed and the "Activity" is activated, and assertCurrentActivity (B) returns true.

Hovewer; if Applicaiton is run in the onCreate method that is in activity A, activity B is opened, but the Robotium cannot be checked with assertCurrentActivity (B). It says that current activity is activity.

MainActivity.class

@Override
    public void onCreate( Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main );
        selector();
        sharedPrefencesHelper.setAppLaunched( true );
        periodsCount = periodListOrdering.getAllPeriodSize();

        if ( periodsCount < 0 )
            intentCalendarActivity();

        replaceNewFragment( EntryFragment.newInstance( this ), ENTRYPAGE_FRAGMENT_TAG );
    }

      

the intentCalendarActivity () method is dispatched to CalendarActivity.class and CalendarActivity is properly opened.

My test code

public void testScenario1() {
        // Kilidi aç
        solo.unlockScreen();
        // DB içindek tüm periodları sil.
        myDatabaseQuery.clearPeriodDB();
        // CalendarActivity için ne olur ne olmaz diye bekleme yapalım.
        solo.waitForActivity( "CalendarActivity" );
        // Takvimi doğrula.
        solo.assertCurrentActivity( "CalendarActivity not found", "CalendarActivity" );
        // Hiç bişey yapmadan geri dön.
        solo.goBack();
        // NoDataMessageActivity acitivity e gönderilmelidir.
        solo.waitForActivity( NO_DATA_MESSAGE_ACTIVITY );
        // NoDataMessageActivity gittiğini doğrula
        solo.assertCurrentActivity( NO_DATA_MESSAGE_ACTIVITY + " is not found", NO_DATA_MESSAGE_ACTIVITY );
        // Bir şey yapmadan geri dön
        solo.goBack();
        }

      

A message that comes from Robotium

junit.framework.ComparisonFailure: CalendarActivity not found expected:<[Calendar]Activity> but was:<[Main]Activity>
at com.robotium.solo.Asserter.assertCurrentActivity(Asserter.java:43)
at com.robotium.solo.Solo.assertCurrentActivity(Solo.java:972)
at com.bitbar.recorder.extensions.ExtSolo.assertCurrentActivity(ExtSolo.java:193)
at com.medyasef.she.NoDataActivityTest.testScenario1(NoDataActivityTest.java:54)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1661)

      

+3


source to share





All Articles