Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application not launch on test started #870

Open
TechnoMag82 opened this issue May 10, 2017 · 4 comments
Open

Application not launch on test started #870

TechnoMag82 opened this issue May 10, 2017 · 4 comments

Comments

@TechnoMag82
Copy link

TechnoMag82 commented May 10, 2017

After start test, application not started automatically for testing. I must manually launch application by tap on icon.

Error by timeout:
junit.framework.AssertionFailedError: Text string: 'Some button' is not found!

My test:
DeliveryActivity is not first Activity in backstack when application launched.

public class DeliveryActivityTest extends ActivityInstrumentationTestCase2 {

  private Solo solo;

  public DeliveryActivityTest() {
    super(DeliveryActivity.class);
  }

  public DeliveryActivityTest(Class<DeliveryActivity> activityClass) {
    super(activityClass);
  }

  public void setUp() throws Exception {
    super.setUp();
    injectInstrumentation(InstrumentationRegistry.getInstrumentation());

    Instrumentation mInstrumentation = getInstrumentation();
    solo = new Solo(mInstrumentation);
    //solo = new Solo(getInstrumentation(), getActivity());
    //solo = new Solo(getInstrumentation(), getActivity());
  }

  @Override
  public void tearDown() throws Exception {
    solo.finishOpenedActivities();
  }

  public void testButton()
  {
    solo.clickOnText("Some button");
  }

}
@andrewleo
Copy link

See the getting started here:https://github.com/RobotiumTech/robotium/wiki/Getting-Started
this may resolve your problem:

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

@TechnoMag82
Copy link
Author

TechnoMag82 commented May 11, 2017

DeliveryActivity extends Fragment.

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

java.lang.RuntimeException: Could not launch activity

@andrewleo
Copy link

public NewRobotiumTest() {
super(PACKAGE_NAME, Class.forName(LAUNCHER_ACTIVITY_CLASSNAME););
}

the first parameter is package name; second is launched activity

@TechnoMag82
Copy link
Author

TechnoMag82 commented May 11, 2017

Thanks. Problem solved with code:

public class DeliveryActivityTest extends ActivityInstrumentationTestCase2 {

  private static final String LAUNCHER_ACTIVITY_CLASSNAME = "com.delivery.example";
  private static Class<?> launchActivityClass;
  static {
    try {
      launchActivityClass = Class.forName(LAUNCHER_ACTIVITY_CLASSNAME);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
  private Solo solo;

  public DeliveryActivityTest(Class<DeliveryActivity> activityClass) {
    super(activityClass);
  }

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

  @Override
  public void tearDown() throws Exception {
    solo.finishOpenedActivities();
    super.tearDown();
  }

  @SuppressWarnings("unchecked")
  public DeliveryActivityTest() {
    super((Class<DeliveryActivity>) launchActivityClass);
  }

  public void testButton()
  {
    solo.clickOnText("Some button");
  }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants