diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateTrackTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateTrackTest.java index af01f1fd1..20680eb84 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateTrackTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateTrackTest.java @@ -32,7 +32,6 @@ import java.util.ArrayList; */ public class CreateTrackTest extends ActivityInstrumentationTestCase2 { - private static final String WAYPOINT_NAME = "testWaypoint"; private Instrumentation instrumentation; private TrackListActivity activityMyTracks; @@ -126,7 +125,7 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2 *
  • The view extends ImageButton.
  • - *
  • The view name equals {@link EndToEndTestUtils#MOREOPTION_CLASSNAME}.
  • + *
  • The view name equals {@link #MOREOPTION_CLASSNAME}.
  • * * @return the more option view. Null means can not find it. */ private static View getMoreOptionView() { - ArrayList allViews = SOLO.getViews(); - for (View view : allViews) { - if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) { - return view; + View viewResult = null; + if (hasActionBar) { + ArrayList allViews = SOLO.getViews(); + for (View view : allViews) { + if (view instanceof ImageButton && view.getClass().getName().equals(MOREOPTION_CLASSNAME)) { + viewResult = view; + break; + } + } + } else { + ArrayList allViews = SOLO.getViews(); + for (View view : allViews) { + if (view.getClass().getName().equals(MENUITEM_CLASSNAME)) { + viewResult = view; + // No break here to get the last menu item. + } } } - return null; + return viewResult; } /** @@ -921,5 +939,41 @@ public class EndToEndTestUtils { .findViewById(R.id.track_controller_total_time)).getText().toString(); Assert.assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew)); } + + + /** + * Creates a way point during track recording. + * + * @param markerNumber of number of previous markers + */ + public static void createWaypoint(int markerNumber) { + findMenuItem(activityMytracks.getString(R.string.menu_markers), true); + if (markerNumber > 0) { + int actualMarkerNumber = SOLO.getCurrentListViews().get(0).getCount(); + Assert.assertEquals(markerNumber, actualMarkerNumber); + } else { + Assert.assertTrue(SOLO.waitForText(activityMytracks + .getString(R.string.marker_list_empty_message))); + } + findMenuItem(activityMytracks.getString(R.string.menu_insert_marker), true); + enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME); + SOLO.clickOnButton(activityMytracks.getString(R.string.generic_add)); + if (hasGpsSingal) { + Assert.assertTrue(SOLO.waitForText(WAYPOINT_NAME, 1, LONG_WAIT_TIME, true)); + } else { + Assert.assertFalse(SOLO.searchText(WAYPOINT_NAME)); + } + SOLO.goBack(); + } + + /** + * Waits a text to disappear. + */ + public static void waitTextToDisappear(String text) { + // The first wait should longer than following waits. + SOLO.waitForText(text, 1, SHORT_WAIT_TIME); + while (SOLO.waitForText(text, 1, 200)) {} + return; + } } \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/MenuItemsTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/MenuItemsTest.java index 1c303a552..6fa645958 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/MenuItemsTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/MenuItemsTest.java @@ -190,19 +190,23 @@ public class MenuItemsTest extends ActivityInstrumentationTestCase2 { - /** - * Set to false as default. - */ - public static boolean testSensor = false; - public SensorTest() { super(TrackListActivity.class); } private Instrumentation instrumentation; - private TrackListActivity activityMyTracks; - public static final String DISABLE_MESSAGE = "This test is disabled"; + private TrackListActivity trackListActivity; + private boolean runTest = false; + private static final String ZEPHYR_NAME = "HXM"; + private static final String POLAR_NAME = "Polar"; @Override protected void setUp() throws Exception { + runTest = BigTestUtils.runSensorTest; super.setUp(); - if (!testSensor) { + if (!runTest) { return; } instrumentation = getInstrumentation(); - activityMyTracks = getActivity(); - EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks); + trackListActivity = getActivity(); + EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); } /** - * Tests connecting to a Zephyr Bluetooth sensor. Before this test, a Zephyr - * sensor must has been paired with the device. + * Tests connecting to a Zephyr Bluetooth sensor while not recording. Before this test, a Zephyr + * sensor must be paired with the device. */ - public void testConnectZephyrBluetoothSensor() { - if (!testSensor) { - Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE); + public void testConnectZephyrBluetoothSensor_notRecording() { + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); return; } - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor)); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor_type)); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks - .getString(R.string.settings_sensor_type_zephyr)); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks - .getString(R.string.settings_sensor_bluetooth_sensor)); - assertTrue(getPairedSensorsNumber() > 0); - EndToEndTestUtils.SOLO.goBack(); - EndToEndTestUtils.SOLO.goBack(); - EndToEndTestUtils.SOLO.goBack(); - assertTrue(checkSensorsStatus()); + bluetoothSensorTest(R.string.settings_sensor_type_zephyr, ZEPHYR_NAME, false); } - + /** - * Tests connecting to a Polar Bluetooth sensor. Before this test, a Polar - * sensor must has been paired with the device. + * Tests connecting to a Zephyr Bluetooth sensor while under recording. Before this test, a Zephyr + * sensor must be paired with the device. */ - public void testConnectPolarBluetoothSensor() { - if (!testSensor) { - Log.i(EndToEndTestUtils.LOG_TAG, DISABLE_MESSAGE); + public void testConnectZephyrBluetoothSensor_underRecording() { + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); return; } - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_settings), true); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor)); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.settings_sensor_type)); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks - .getString(R.string.settings_sensor_type_polar)); - EndToEndTestUtils.SOLO.clickOnText(activityMyTracks - .getString(R.string.settings_sensor_bluetooth_sensor)); - assertTrue(getPairedSensorsNumber() > 0); - EndToEndTestUtils.SOLO.goBack(); - EndToEndTestUtils.SOLO.goBack(); - EndToEndTestUtils.SOLO.goBack(); - assertTrue(checkSensorsStatus()); + bluetoothSensorTest(R.string.settings_sensor_type_zephyr, ZEPHYR_NAME, true); } /** - * Get the number of paired sensors. + * Tests connecting to a Polar Bluetooth sensor while not recording. Before this test, a Polar + * sensor must be paired with the device. + */ + public void testConnectPolarBluetoothSensor_notRecording() { + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); + return; + } + bluetoothSensorTest(R.string.settings_sensor_type_polar, POLAR_NAME, false); + } + + /** + * Tests connecting to a Polar Bluetooth sensor while under recording. Before this test, a Polar + * sensor must be paired with the device. + */ + public void testConnectPolarBluetoothSensor_underRecording() { + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); + return; + } + bluetoothSensorTest(R.string.settings_sensor_type_polar, POLAR_NAME, true); + } + + /** + * Set the paired sensor. * - * @return the number of paired sensors + * @param sensorTypeStringId the string id of paired sensors type + * @param nameString part of the sensor name string which can distinguish + * different Bluetooth sensors + * @param isUnderRecording true means test under recording */ - private int getPairedSensorsNumber() { + private void bluetoothSensorTest(int sensorTypeStringId, String nameString, + boolean isUnderRecording) { + EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), true); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor)); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor_type)); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(sensorTypeStringId)); + checkPairedSensorsNumber(nameString); + // Set the paired sensor. + EndToEndTestUtils.SOLO.clickOnText(nameString); + EndToEndTestUtils.SOLO.goBack(); + EndToEndTestUtils.SOLO.goBack(); + if (isUnderRecording) { + assertTrue(checkSensorsStatus_underRecording()); + } else { + assertTrue(checkSensorsStatus_notRecording()); + } + } + + /** + * Checks the number of paired sensors. + */ + private void checkPairedSensorsNumber(String nameString) { + EndToEndTestUtils.SOLO.clickOnText(trackListActivity + .getString(R.string.settings_sensor_bluetooth_sensor)); + instrumentation.waitForIdleSync(); ArrayList allListViews = EndToEndTestUtils.SOLO.getCurrentListViews(); int number = allListViews.get(0).getCount(); - return number; + if (number > 0 + && EndToEndTestUtils.SOLO.waitForText(nameString, 1, EndToEndTestUtils.SHORT_WAIT_TIME)) { + return; + } + + Log.i(EndToEndTestUtils.LOG_TAG, "No sensor is paried"); + fail("No bluetooth sensor is paired. Please pair at Settings->Bluetooth before running the test."); } /** - * Checks whether the sensor is connected with MyTracks. + * Tests connecting to a cadence ANT+ sensor. + */ + public void testConnectANTSensor_Cadence() { + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); + return; + } + useANTSeonsor(); + assertTrue(checkSensorsStatus_notRecording()); + checkANTSensorsStatus(R.id.sensor_state_cadence); + } + + /** + * Tests connecting to cadence and heart rate ANT+ sensors at the same time. + */ + public void testConnectTwoANTSensors() { + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); + return; + } + useANTSeonsor(); + assertTrue(checkSensorsStatus_notRecording()); + checkANTSensorsStatus(R.id.sensor_state_cadence); + checkANTSensorsStatus(R.id.sensor_state_heart_rate); + } + + /** + * Sets the setting to use ANT+ sensor + */ + private void useANTSeonsor() { + EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), true); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor)); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.settings_sensor_type)); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity + .getString(R.string.settings_sensor_type_ant)); + EndToEndTestUtils.SOLO.goBack(); + EndToEndTestUtils.SOLO.goBack(); + } + + /** + * Checks whether the ANT+ sensor is connected with MyTracks. + * + * @param viewID the id to check which is not equal with None + */ + private void checkANTSensorsStatus(int viewID) { + TextView sensorValueText = ((TextView) EndToEndTestUtils.SOLO.getCurrentActivity() + .findViewById(viewID)); + assertNotNull(sensorValueText); + String realValue = sensorValueText.getText().toString(); + String noneValue = trackListActivity.getString(R.string.settings_sensor_type_none); + assertNotSame(realValue, noneValue); + } + + /** + * Checks whether the sensor is connected with MyTracks during recording. * * @return true means the sensor is connected with MyTracks */ - private boolean checkSensorsStatus() { + private boolean checkSensorsStatus_underRecording() { + EndToEndTestUtils.instrumentation.waitForIdleSync(); + EndToEndTestUtils.startRecording(); + EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_sensor_state), true); + boolean result = EndToEndTestUtils.SOLO.waitForText( + trackListActivity.getString(R.string.sensor_state_connected), 1, + EndToEndTestUtils.LONG_WAIT_TIME); + EndToEndTestUtils.stopRecording(true); + return result; + } + + /** + * Checks whether the sensor is connected with MyTracks while not under recording. + * + * @return true means the sensor is connected with MyTracks + */ + private boolean checkSensorsStatus_notRecording() { EndToEndTestUtils.instrumentation.waitForIdleSync(); EndToEndTestUtils.createTrackIfEmpty(0, false); - EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_sensor_state), true); + EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_sensor_state), true); return EndToEndTestUtils.SOLO.waitForText( - activityMyTracks.getString(R.string.sensor_state_connected), 1, - EndToEndTestUtils.NORMAL_WAIT_TIME); + trackListActivity.getString(R.string.sensor_state_connected), 1, + EndToEndTestUtils.LONG_WAIT_TIME); } - + @Override protected void tearDown() throws Exception { - if (!testSensor) { + if (!runTest) { return; } EndToEndTestUtils.SOLO.finishOpenedActivities(); diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/StressTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/StressTest.java index 092abd058..ab575de47 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/StressTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/others/StressTest.java @@ -24,58 +24,58 @@ import android.test.ActivityInstrumentationTestCase2; import android.util.Log; /** - * Tests Rotation of MyTracks. + * Stress test of MyTracks. * * @author Youtao Liu */ public class StressTest extends ActivityInstrumentationTestCase2 { - /** - * Set to false as default. - */ - public static boolean testStress = false; - public static final int MINUTES_FOR_EACH_TEST = 30; - public static final int MILLI_SECOND_IN_ONE_MINUTE = 60 * 1000; - long startTime = 0; - int trackNumber; + private static final int TEST_DURATION_IN_MILLISECONDS = 30 * 60 * 1000; + private static final int MAX_TRACK_NUMBER = 30; + private boolean runTest = false; + + private long startTime = 0; + private int numberOfTracks; public StressTest() { super(TrackListActivity.class); } private Instrumentation instrumentation; - private TrackListActivity activityMyTracks; + private TrackListActivity trackListActivity; @Override protected void setUp() throws Exception { + runTest = BigTestUtils.runStressTest; super.setUp(); - if (!testStress) { + if (!runTest) { return; } instrumentation = getInstrumentation(); - activityMyTracks = getActivity(); - EndToEndTestUtils.setupForDebug(instrumentation, activityMyTracks); + trackListActivity = getActivity(); + EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); startTime = System.currentTimeMillis(); - EndToEndTestUtils.emulatorPort = 5568; } /** - * Records tracks and delete them when there are more than 30 tracks.. + * Records tracks and deletes them when there are more than + * {@link #MAX_TRACK_NUMBER} tracks. Keeps sending different GPS locations in + * each track, making it closer to the real stress. */ public void testRecordAndDeleteTracks() { - if (!testStress) { - Log.i(EndToEndTestUtils.LOG_TAG, SensorTest.DISABLE_MESSAGE); + if (!runTest) { + Log.i(EndToEndTestUtils.LOG_TAG, BigTestUtils.DISABLE_MESSAGE); return; } - for (int i = 0; (System.currentTimeMillis() - startTime) / MILLI_SECOND_IN_ONE_MINUTE < MINUTES_FOR_EACH_TEST; i++) { + for (int i = 0; (System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS; i++) { EndToEndTestUtils.startRecording(); // Points in a tracks keep increasing. EndToEndTestUtils.sendGps(i * 10, 0, 10); EndToEndTestUtils.stopRecording(true); EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.instrumentation.waitForIdleSync(); - trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount(); - if (trackNumber > 30) { + numberOfTracks = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount(); + if (numberOfTracks > MAX_TRACK_NUMBER) { EndToEndTestUtils.deleteAllTracks(); } logStatus(i); @@ -83,55 +83,88 @@ public class StressTest extends ActivityInstrumentationTestCase2