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 launchCreateExperimentActivity(ActivityInstrumentationTestCase2<?> testCase,
        Activity activity) {/*ww  w .j av  a2 s  .c  o  m*/

    // click the Create-New-Experiment button
    ActivityMonitor activityMonitor = testCase.getInstrumentation()
            .addMonitor(CreateExperimentActivity.class.getName(), null, false);

    Button buttonCreateExperiment = (Button) activity.findViewById(R.id.button_create_experiment);
    Assert.assertNotNull("The Create-Experiment Button should not be null", buttonCreateExperiment);

    TouchUtils.clickView(testCase, buttonCreateExperiment);

    testCase.getInstrumentation().waitForIdleSync();

    activity = testCase.getInstrumentation().waitForMonitor(activityMonitor);

    testCase.getInstrumentation().removeMonitor(activityMonitor);
    return activity;
}

From source file:com.chalmers.schmaps.test.GoogleMapSearchLocationTest.java

/**
 * Searches for a room that is known to exist in the database and tests
 * that what is drawn on the map has the same attributes as the one that
 * was queried./*  ww w  .  ja v a  2  s  .c o  m*/
 */
public void testSearchForARoom() {
    TouchUtils.tapView(this, this.lectureEdit);
    super.sendKeys("R U N A N");
    super.getInstrumentation().waitForIdleSync();
    TouchUtils.clickView(this, this.editButton);
    super.getInstrumentation().waitForIdleSync();
    List<Overlay> overlays = mapview.getOverlays();

    //Test case for when u dont have a position from user
    //MapItemizedOverlay tempTestOverlay = (MapItemizedOverlay) overlays.get(0);

    //Test case for when u get a position for the user
    MapItemizedOverlay tempTestOverlay = (MapItemizedOverlay) overlays.get(2);

    GeoPoint roomGP = new GeoPoint(ARBITRARYLATPOS, ARBITRARYLONGPOS);

    assertEquals(roomGP, tempTestOverlay.getItem(0).getPoint());
    assertEquals("Sven Hultins gata 2", tempTestOverlay.getItem(0).getTitle());
    assertEquals("Floor 1", tempTestOverlay.getItem(0).getSnippet());
}

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

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

    // choose to enter tags
    CreateExperimentActivity createExperimentActivity = (CreateExperimentActivity) activity;

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

    ListView listViewOperations = (ListView) fragment.getView().findViewById(R.id.lv_operations);
    Assert.assertNotNull("The operations ListView should not be null.", listViewOperations);
    Assert.assertEquals("The operations ListView should has 3 items", listViewOperations.getCount(), 3);

    TouchUtils.clickView(testCase, listViewOperations.getChildAt(0));

    testCase.getInstrumentation().waitForIdleSync();

    // enter a random number of tags without description
    fragment = createExperimentActivity.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The ExperimentEditTagsFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentEditTagsFragment.",
            fragment instanceof ExperimentEditTagsFragment);

    final EditText editTextTag = (EditText) fragment.getView().findViewById(R.id.edittext_tag);
    Assert.assertNotNull("EditText for Tag should not be null.", editTextTag);

    Button buttonAddTag = (Button) fragment.getView().findViewById(R.id.btn_add_tag);
    Assert.assertNotNull("The Add-Tag button should not be null.", buttonAddTag);

    int numberOfTags = (int) (Math.random() * maximumNumberOfTags + 1);
    for (int i = 0; i < numberOfTags; i++) {
        final String strTag = "Tag_" + (i + 1);
        createExperimentActivity.runOnUiThread(new Runnable() {
            @Override/*w  w w. j a  v a  2  s .  c om*/
            public void run() {
                editTextTag.setText(strTag);
            }
        });
        testCase.getInstrumentation().waitForIdleSync();
        TouchUtils.clickView(testCase, buttonAddTag);
        testCase.getInstrumentation().waitForIdleSync();
    }

    ListView listViewTags = (ListView) fragment.getView().findViewById(R.id.listview_tags);
    Assert.assertNotNull("The ListView for entered tags should not be null.", listViewTags);
    Assert.assertEquals("The number of tags entered must be " + numberOfTags, listViewTags.getCount(),
            numberOfTags);
}

From source file:com.chalmers.schmaps.test.CheckInActivityTest.java

/**
 * Is testing that is testing that the regex is working
 * Only allowing letters and numbers/*w  w w .ja  v a  2s.  co m*/
 */
public void testAddNameRegex() {
    TouchUtils.tapView(this, this.nameEdit);

    super.sendKeys("R U N E ");
    super.getInstrumentation().waitForIdleSync();
    super.sendKeys(KeyEvent.KEYCODE_APOSTROPHE);

    super.getInstrumentation().waitForIdleSync();
    TouchUtils.clickView(this, this.checkInButton);
    super.getInstrumentation().waitForIdleSync();

    activity.getInputName();
    assertEquals("rune", activity.getInputName());

}

From source file:com.chalmers.schmaps.test.GoogleMapSearchLocationTest.java

/**
 * Tests that a dialog is shown if a room is not found by querying for
 * something that does not exist within the database and confirms that
 * a dialog is shown upon the query.//from  w w w . j a  v  a2s .  c om
 */
public void testDialogRoomNotFound() {
    Dialog showingDialog = null;
    TouchUtils.tapView(this, this.lectureEdit);
    super.sendKeys(KeyEvent.KEYCODE_BACKSLASH);
    super.sendKeys("R O O M THATDOESNOTEXIST");
    super.sendKeys(KeyEvent.KEYCODE_POUND);
    super.getInstrumentation().waitForIdleSync();
    TouchUtils.clickView(this, this.editButton);
    super.getInstrumentation().waitForIdleSync();
    try {
        Field dialogRoomNotFound = activity.getClass().getDeclaredField("dialog");
        dialogRoomNotFound.setAccessible(true);
        showingDialog = (Dialog) dialogRoomNotFound.get(this.activity);
    } catch (Exception e) {
    }
    assertTrue(showingDialog.isShowing());
}

From source file:com.chalmers.schmaps.test.GoogleMapSearchLocationTest.java

/**
 * Makes sure that the regex function works as intended by 
 * inserting spaces and special characters into the query
 * and confirming that still the right input was queried.
 *//*w w  w .  j a  va 2 s . c  o m*/
public void testRegexForRoom() {
    TouchUtils.tapView(this, this.lectureEdit);
    super.sendKeys(KeyEvent.KEYCODE_BACKSLASH);
    super.sendKeys("R U N A N ");
    super.sendKeys(KeyEvent.KEYCODE_POUND);
    super.getInstrumentation().waitForIdleSync();
    TouchUtils.clickView(this, this.editButton);
    super.getInstrumentation().waitForIdleSync();
    assertEquals("runan", activity.getRoomToFind());
}

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

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

    // choose to select sensors
    CreateExperimentActivity createExperimentActivity = (CreateExperimentActivity) activity;

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

    ListView listViewOperations = (ListView) fragment.getView().findViewById(R.id.lv_operations);
    Assert.assertNotNull("The operations ListView should not be null.", listViewOperations);
    Assert.assertEquals("The operations ListView should has 3 items", listViewOperations.getCount(), 3);

    TouchUtils.clickView(testCase, listViewOperations.getChildAt(2));

    testCase.getInstrumentation().waitForIdleSync();

    // select the 1st sensor
    fragment = createExperimentActivity.getSupportFragmentManager().findFragmentById(R.id.fragment_container);
    Assert.assertNotNull("The ExperimentSensorSelectionFragment should not be null.", fragment);
    Assert.assertTrue("The fragment should be an ExperimentSensorListFragment.",
            fragment instanceof ExperimentSensorSelectionFragment);

    RelativeLayout layout = (RelativeLayout) fragment.getView().findViewById(R.id.layout_sensor_selection_list);
    Assert.assertNotNull("The Sensor ListView should not be null.", layout);
    ListView sensorListView = null;
    for (int i = 0; i < layout.getChildCount(); i++) {
        View child = layout.getChildAt(i);
        if (child instanceof ListView)
            sensorListView = (ListView) child;
    }//  w  ww.j  ava 2 s .com
    Assert.assertNotNull("The Sensor ListView should not be null", sensorListView);

    int numberOfSensorsToSelect = (int) (Math.random() * sensorListView.getCount()) + 1;
    int numberOfSensorsSelected = 0;
    int sensorPosition = 0;
    while (numberOfSensorsSelected < numberOfSensorsToSelect) {
        double rn = Math.random();
        if ((sensorListView.getCount() - sensorPosition) * rn >= numberOfSensorsToSelect
                - numberOfSensorsSelected) {
            sensorPosition++;
        } else {
            TouchUtils.clickView(testCase, sensorListView.getChildAt(sensorPosition).findViewById(R.id.check));
            sensorPosition++;
            numberOfSensorsSelected++;
        }
    }

    testCase.getInstrumentation().waitForIdleSync();
}

From source file:com.chalmers.schmaps.test.GoogleMapSearchLocationTest.java

/**
 * Tests that the database is connected and that a response from the google directions api is recieved
 * If the jsonobject is received the boolean running is set to true
 *///from   w  ww  .  ja  v  a 2 s.c om
public void testConnectionToDirections() {
    TouchUtils.tapView(this, this.lectureEdit);
    super.sendKeys("R U N A N ");
    super.getInstrumentation().waitForIdleSync();
    TouchUtils.clickView(this, this.editButton);
    super.getInstrumentation().waitForIdleSync();

    activity.walkningDirections();

    assertEquals(true, activity.getIsAsyncTaskRunning());
}

From source file:com.chalmers.schmaps.test.GoogleMapSearchLocationTest.java

/**
 * Tests that the getdirectionsbutton is working, that the asynctask method has executed
 *///from   w ww .  j  a va 2s . co m
public void testDirectionsButton() {
    TouchUtils.tapView(this, this.lectureEdit);
    super.sendKeys("R U N A N ");
    super.getInstrumentation().waitForIdleSync();
    TouchUtils.clickView(this, this.editButton);
    super.getInstrumentation().waitForIdleSync();

    TouchUtils.clickView(this, this.directionsButton);
    super.getInstrumentation().waitForIdleSync();

    assertEquals(true, activity.getIsAsyncTaskRunning());
}

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

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

    Button buttonRunExperiment = (Button) activity.findViewById(R.id.button_experiment_run);
    Assert.assertNotNull("The Run-Experiment button should not be null.", buttonRunExperiment);

    TouchUtils.clickView(testCase, buttonRunExperiment);
    testCase.getInstrumentation().waitForIdleSync();
}