3

I am trying to write a test that performs a workflow in my app. However; I need to split my test into two parts. The scenario goes something like this:

I start my app, then it starts a Gallery to select an image then goes back to my app to continue with the workflow.

The problem I'm having is that I can't automate actions in the Gallery, so this requires some manual action. So my plan is to automate the first part i.e. start my app and start Gallery then manually select an image and then run the second part of my automated test.

The problem is at the end of the first automation part the activity is closed even if I don't do a tearDown step and call activity.finish()

I have included an example of the code I'm using. So if you could point out what I'm doing wrong here that would be awesome. I should mention that I'm using Robotium for my automation.

package com.myapp.android.testWithAPK; 
import com.jayway.android.robotium.solo.Solo; 
import android.test.ActivityInstrumentationTestCase2; 
public class MyTest extends ActivityInstrumentationTestCase2 { 
        private static final String TARGET_PACKAGE_ID = "com.myapp.android"; 
        private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = 
"com.myapp.android.ui.Main"; 
        private static Class<?> launcherActivityClass; 
        static { 
                try { 
                        launcherActivityClass = Class 
                                        .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME); 
                } catch (ClassNotFoundException e) { 
                        throw new RuntimeException(e); 
                } 
        } 
        @SuppressWarnings("unchecked") 
        public MyTest() throws ClassNotFoundException { 
                super(launcherActivityClass); 
        } 
        private Solo solo; 
        @Override 
        protected void setUp() throws Exception { 
                solo = new Solo(getInstrumentation()); 
        } 
        public void testCreatePostCard() throws InterruptedException{ 
                solo.clickOnText("Make a postcard"); 
                solo.clickOnText("Choose photo"); 
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
limmy
  • 73
  • 1
  • 7

1 Answers1

0

I am guessing a little because your code is cut off but I believe what you are doing is running one test then doing the manual step then running the second test (via another adb command) Am i correct? if so this will be your issue as every time you start a new test it will GC away old activities of your application. The way to solve this will be to create one test that does both parts with a bit in the middle of your test waiting for the next part of the test to be in the correct state, the way to test this will be just to use a sleep command for a few seconds and if this works make this code better by putting in a wait section waiting for an element only present on the screen the application returns to.

Paul Harris
  • 5,769
  • 1
  • 25
  • 41