1

I'm running an automated test in Eclipse using Robotium (running it as an Android jUnit test), when I first launch the emulator the app won't run in the foreground and the test fails. If I keep the emulator open press the 'main menu' button then run the test it works fine. The test is running a few events in a test project which is a notepad.

Any solutions to pushing the app to the foreground when it first opens the emulator?

Here's the manifest from the Test Project

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.jayway.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-library android:name="android.test.runner" />

Here's the manifest from the actual project

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.notepad" >

    <application android:icon="@drawable/app_notes"
        android:label="@string/app_name" >
        <provider android:name="NotePadProvider"
            android:authorities="com.example.notepad.provider.NotePad" />

        <activity android:name="NotesList"
            android:label="@string/title_notes_list">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="android.intent.action.PICK" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.GET_CONTENT" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>
        </activity>

        <activity android:name="NoteEditor"
            android:theme="@android:style/Theme.Light"
            android:configChanges="keyboardHidden|orientation">
            <!-- This filter says that we can view or edit the data of
                 a single note -->
            <intent-filter android:label="@string/resolve_edit">
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.EDIT" />
                <action android:name="com.android.notes.action.EDIT_NOTE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
            </intent-filter>
        </activity>

        <activity android:name="NotesLiveFolder" android:label="@string/live_folder_name"
            android:icon="@drawable/live_folder_notes">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>

    <uses-sdk android:minSdkVersion="10"/>
</manifest>
    </application>
    <uses-sdk android:minSdkVersion="10" />
    <instrumentation android:targetPackage="com.example.android.notepad"   android:name="android.test.InstrumentationTestRunner" />
</manifest> 
j_m
  • 21
  • 6
  • Could I suggest you add add some relevant code; what it is you are testing; and may be some log output for others to go. Also, at what point in the [Activity life-cycle](http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle) is your app getting stuck, assuming you run this in debug to check? If not, maybe [this question](http://stackoverflow.com/questions/5504632/how-can-i-tell-if-android-app-is-running-in-the-foreground) can help. – Chilledrat Apr 24 '12 at 20:43
  • I put up the manifest XML code above, this test won't run in debug it's a junit test app. The log is quite long and there are no errors. The app won't open with the emulator when it gets to the homescreen, you need to press the menu button for the app to come to the foreground. – j_m Apr 25 '12 at 08:48

1 Answers1

1

I solved this using this command.

adb shell input keyevent 82

This wakes the emulator/device.

j_m
  • 21
  • 6