Example usage for android.test TouchUtils clickView

List of usage examples for android.test TouchUtils clickView

Introduction

In this page you can find the example usage for android.test TouchUtils clickView.

Prototype

public static void clickView(InstrumentationTestCase test, View v) 

Source Link

Document

Simulate touching the center of a view and releasing.

Usage

From source file:sysnetlab.android.sdc.test.TestHelper.java

public static Activity stopExperiment(ActivityInstrumentationTestCase2<?> testCase, Activity activity) {
    Assert.assertTrue("The activity must be a CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);

    Fragment fragment = ((CreateExperimentActivity) activity).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The ExperimentRunFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentRunFragment.",
            fragment instanceof ExperimentRunFragment);

    Button buttonExperimentDone = (Button) fragment.getView().findViewById(R.id.button_experiment_done);
    Assert.assertNotNull("The Experiment-Done button shoud not be null.", buttonExperimentDone);

    TouchUtils.clickView(testCase, buttonExperimentDone);
    testCase.getInstrumentation().waitForIdleSync();

    AlertDialog dialog = ((CreateExperimentActivity) activity).getAlertDialog();
    Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);

    ActivityMonitor monitor = testCase.getInstrumentation()
            .addMonitor(SensorDataCollectorActivity.class.getName(), null, false);

    TouchUtils.clickView(testCase, positiveButton);
    testCase.getInstrumentation().waitForIdleSync();

    SensorDataCollectorActivity sensorDataCollectorActivity = (SensorDataCollectorActivity) testCase
            .getInstrumentation().waitForMonitor(monitor);
    testCase.getInstrumentation().removeMonitor(monitor);
    Assert.assertNotNull("SensorDataCollector Activity was not loaded", sensorDataCollectorActivity);

    return sensorDataCollectorActivity;
}

From source file:sysnetlab.android.sdc.test.TestHelper.java

public static Activity viewMostRecentExperiment(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {/*from ww w.j a v  a 2s  .  c o  m*/
    // view the most recent experiment
    Fragment fragment = ((SensorDataCollectorActivity) activity).getSupportFragmentManager()
            .findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The Sensor List Fragment should not be null.", fragment);

    ListView listView = ((ListFragment) fragment).getListView();
    Assert.assertNotNull("ListView should not be null.", listView);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(ViewExperimentActivity.class.getName(),
            null, false);
    TouchUtils.clickView(testCase, listView.getChildAt(listView.getHeaderViewsCount()));
    testCase.getInstrumentation().waitForIdleSync();

    ViewExperimentActivity viewExperimentActivity = (ViewExperimentActivity) testCase.getInstrumentation()
            .waitForMonitor(monitor);
    Assert.assertTrue("activity should be a ViewExperimentActivity.",
            viewExperimentActivity instanceof ViewExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    // clone the experiment
    testCase.getInstrumentation().waitForIdleSync();
    return viewExperimentActivity;
}

From source file:sysnetlab.android.sdc.test.TestHelper.java

public static Activity cloneExperiment(ActivityInstrumentationTestCase2<?> testCase, Activity activity) {
    Assert.assertTrue("The acitivty must be a ViewExperimentActivity.",
            activity instanceof ViewExperimentActivity);

    Button buttonCloneExperiment = (Button) activity.findViewById(R.id.button_experiment_view_clone);
    Assert.assertNotNull("Button should not be null.", buttonCloneExperiment);

    ActivityMonitor monitor = testCase.getInstrumentation().addMonitor(CreateExperimentActivity.class.getName(),
            null, false);/*from ww w. j  ava  2  s . c  o m*/
    TouchUtils.clickView(testCase, buttonCloneExperiment);
    activity = testCase.getInstrumentation().waitForMonitorWithTimeout(monitor, 5000);
    Assert.assertTrue("activity should be CreateExperimentActivity.",
            activity instanceof CreateExperimentActivity);
    testCase.getInstrumentation().removeMonitor(monitor);

    return activity;
}