diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java index df6702e41..c15b0c883 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java @@ -53,46 +53,39 @@ import junit.framework.Assert; * @author Youtao Liu */ public class EndToEndTestUtils { - - private static final String ANDROID_LOCAL_IP = "10.0.2.2"; - // usually 5554. public static int emulatorPort = 5556; - + // usually 5554. private static final int ORIENTATION_PORTRAIT = 1; private static final int ORIENTATION_LANDSCAPE = 0; - // Pause 200ms between each send. - static final double START_LONGITUDE = 51; - static final double START_LATITUDE = -1.3f; - static final double DELTA_LONGITUDE = 0.0005f; - static final double DELTA_LADITUDE = 0.0005f; - static final String WAYPOINT_NAME = "testWaypoint"; - static final String WAYPOINT_TYPE = "testWaypoinType"; - static final String WAYPOINT_DESC = "testWaypointDesc"; - private static final String NO_GPS_MESSAGE_PREFIX = "GPS is not available"; + private static final String ANDROID_LOCAL_IP = "10.0.2.2"; + private static final String NO_GPS_MESSAGE_PREFIX = "GPS is not available"; private static final String MOREOPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton"; private static final String MENUITEM_CLASSNAME = "com.android.internal.view.menu.IconMenuItemView"; - static final String DEFAULTACTIVITYTYPE = "TestActivity"; - public static String activityType = DEFAULTACTIVITYTYPE; - static String trackName; - static final String TRACK_NAME_PREFIX = "testTrackName"; - static String trackDesc; - static final String TRACK_DESC_PREFIX = "testTrackDesc"; - static final String GPX = "gpx"; - static final String KML = "kml"; - static final String CSV = "csv"; - static final String TCX = "tcx"; - static final String BACKUPS = "backups"; - static final String MENU_MORE = "More"; + // Pause 200ms between each send. + public static final double START_LONGITUDE = 51; + public static final double START_LATITUDE = -1.3f; + public static final double DELTA_LONGITUDE = 0.0005f; + public static final double DELTA_LADITUDE = 0.0005f; + public static final String WAYPOINT_NAME = "testWaypoint"; + public static final String WAYPOINT_TYPE = "testWaypoinType"; + public static final String WAYPOINT_DESC = "testWaypointDesc"; + public static final String DEFAULTACTIVITYTYPE = "TestActivity"; + public static final String TRACK_NAME_PREFIX = "testTrackName"; + public static final String TRACK_DESC_PREFIX = "testTrackDesc"; + public static final String GPX = "gpx"; + public static final String KML = "kml"; + public static final String CSV = "csv"; + public static final String TCX = "tcx"; + public static final String BACKUPS = "backups"; + public static final String MENU_MORE = "More"; + public static final String LOG_TAG = "MyTracksTest"; // Following is some check strings in English and Chinese private static final HashMap RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL = new HashMap(); private static final HashMap KM_MULTILINGUAL = new HashMap(); private static final HashMap MILE_MULTILINGUAL = new HashMap(); - public static String RELATIVE_STARTTIME_POSTFIX = ""; - public static String KM = ""; - public static String MILE = ""; public static final int TINY_WAIT_TIME = 200; public static final int VERY_SHORT_WAIT_TIME = 500; @@ -101,7 +94,13 @@ public class EndToEndTestUtils { public static final int LONG_WAIT_TIME = 15000; public static final int SUPER_LONG_WAIT_TIME = 100000; + public static String activityType = DEFAULTACTIVITYTYPE; + public static String RELATIVE_STARTTIME_POSTFIX = ""; + public static String KM = ""; + public static String MILE = ""; public static String deviceLanguage = ""; + public static String trackName; + public static String trackDesc; static { RELATIVE_STARTTIME_POSTFIX_MULTILINGUAL.put("es", "mins ago"); @@ -125,15 +124,17 @@ public class EndToEndTestUtils { public static Solo SOLO; public static Instrumentation instrumentation; - static TrackListActivity activityMytracks; - // Check whether the UI has an action bar which is related with the version of - // Android OS. - static boolean hasActionBar = false; - static boolean isEmulator = true; - static boolean hasGpsSingal = true; - static boolean isCheckedFirstLaunch = false; - static boolean isGooglePlayServicesLatest = true; - public static final String LOG_TAG = "MyTracksTest"; + public static TrackListActivity activityMytracks; + + /* + * Check whether the UI has an action bar which is related with the version of + * Android OS. + */ + public static boolean hasActionBar = false; + public static boolean isEmulator = true; + public static boolean hasGpsSingal = true; + public static boolean isCheckedFirstLaunch = false; + public static boolean isGooglePlayServicesLatest = true; private EndToEndTestUtils() {} diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/ExportAndImportTest.java.orig b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/ExportAndImportTest.java.orig new file mode 100644 index 000000000..3ad499328 --- /dev/null +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/ExportAndImportTest.java.orig @@ -0,0 +1,251 @@ +/* + * Copyright 2012 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.android.apps.mytracks.endtoendtest; + +import com.google.android.apps.mytracks.TrackListActivity; +import com.google.android.apps.mytracks.util.FileUtils; +import com.google.android.maps.mytracks.R; + +import android.app.Instrumentation; +import android.test.ActivityInstrumentationTestCase2; + +import java.io.File; + +/** + * Tests the import and export of MyTracks. + * + * @author Youtao Liu + */ +public class ExportAndImportTest extends ActivityInstrumentationTestCase2 { + + private Instrumentation instrumentation; + private TrackListActivity activityMyTracks; + + public ExportAndImportTest() { + super(TrackListActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + instrumentation = getInstrumentation(); + activityMyTracks = getActivity(); + EndToEndTestUtils.setupForAllTest(instrumentation, activityMyTracks); + } + + /** + * Tests export and import tracks after creating a track with Gps signal and + * an empty track. + */ + public void testExportAndImportTracks() { + // Create a new track with 3 gps data. + EndToEndTestUtils.createTrackIfEmpty(3, true); + instrumentation.waitForIdleSync(); + + // Create a empty track. + EndToEndTestUtils.createSimpleTrack(0, true); + instrumentation.waitForIdleSync(); + checkExportAndImport(); + } + + /** + * Tests export and import track. Then check the properties of this track. + */ + public void testExportAndImportTrack_properties() { + EndToEndTestUtils.deleteAllTracks(); + + // Create a new track with two markers. + EndToEndTestUtils.startRecording(); + instrumentation.waitForIdleSync(); + + // Send Gps before creating marker. + EndToEndTestUtils.sendGps(2); + EndToEndTestUtils.createWaypoint(0); + EndToEndTestUtils.sendGps(2, 2); + EndToEndTestUtils.createWaypoint(1); + EndToEndTestUtils.sendGps(2, 4); + + // Back to tracks list. + EndToEndTestUtils.SOLO.goBack(); + instrumentation.waitForIdleSync(); + EndToEndTestUtils.stopRecording(true); + + // Export this track and then delete it. + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX); + + // Click to export tracks(At least one track) to Gpx files. + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true); + EndToEndTestUtils.SOLO + .clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format), + EndToEndTestUtils.GPX.toUpperCase())); + EndToEndTestUtils.SOLO.waitForText(activityMyTracks + .getString(R.string.external_storage_save_success)); + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + EndToEndTestUtils.deleteAllTracks(); + + // Import this tracks. + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import), true); + EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString( + R.string.external_storage_import_success_count).split("%")[0]); + + /* + * Check import tracks should be equal with the sum of trackNumber and + * gpxFilesNumber; + */ + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + instrumentation.waitForIdleSync(); + + // Check the track name, activity and description. + assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName)); + EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.trackName); + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_edit), true); + instrumentation.waitForIdleSync(); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackName)); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.activityType)); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.trackDesc)); + EndToEndTestUtils.SOLO.clickOnText(activityMyTracks.getString(R.string.generic_cancel)); + + // Check the markers. + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true); + + // The first marker. + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_NAME + 1)); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_TYPE + 1)); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_DESC + 1)); + + // The second marker. + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_NAME + 2)); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_TYPE + 2)); + assertTrue(EndToEndTestUtils.SOLO.searchText(EndToEndTestUtils.WAYPOINT_DESC + 2)); + } + + /** + * Tests export and import tracks after creating a track with Gps signal and + * an empty track. Both tracks are paused during recording. + */ + public void testExportAndImportTracks_pausedTrack() { + EndToEndTestUtils.deleteAllTracks(); + // Create a new track with 3 gps data. + EndToEndTestUtils.createTrackWithPause(3); + instrumentation.waitForIdleSync(); + EndToEndTestUtils.SOLO.goBack(); + + // Create a empty track. + EndToEndTestUtils.createTrackWithPause(0); + instrumentation.waitForIdleSync(); + EndToEndTestUtils.SOLO.goBack(); + instrumentation.waitForIdleSync(); + checkExportAndImport(); + } + + /** + * Tests export and import tracks. + *
    + *
  • Create two tracks, one of them is empty(Have no Gps data).
  • + *
  • Tests import when there is no track file.
  • + *
  • Tests export tracks to Gpx files.
  • + *
  • Tests import files to tracks.
  • + *
  • Tests export tracks to Kml files.
  • + *
+ */ + private void checkExportAndImport() { + // Delete all exported gpx and kml tracks. + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.GPX); + EndToEndTestUtils.deleteExportedFiles(EndToEndTestUtils.KML); + int gpxFilesNumber = 0; + File[] allGpxFiles = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX); + + // For the first export, there is no MyTracks folder. + if (allGpxFiles != null) { + gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length; + } + + // Get track number in current track list of MyTracks. + int trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount(); + + // No file to imported. + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import), true); + EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString( + R.string.external_storage_import_error_no_file, + FileUtils.buildExternalDirectoryPath(EndToEndTestUtils.GPX))); + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + + // Click to export tracks(At least one track) to Gpx files. + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true); + EndToEndTestUtils.SOLO + .clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format), + EndToEndTestUtils.GPX.toUpperCase())); + EndToEndTestUtils.SOLO.waitForText(activityMyTracks + .getString(R.string.external_storage_save_success)); + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + + // Check export file. + assertEquals(gpxFilesNumber + trackNumber, + EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length); + instrumentation.waitForIdleSync(); + + // Click to import track. + gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length; + trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount(); + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_import), true); + EndToEndTestUtils.rotateAllActivities(); + + /* + * Wait for the prefix of import success string is much faster than wait the + * whole string. + */ + EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString( + R.string.external_storage_import_success_count).split("%")[0]); + + /* + * Check import tracks should be equal with the sum of trackNumber and + * gpxFilesNumber; + */ + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + instrumentation.waitForIdleSync(); + assertTrue(EndToEndTestUtils.SOLO.waitForText(EndToEndTestUtils.trackName)); + assertEquals(trackNumber + gpxFilesNumber, EndToEndTestUtils.SOLO.getCurrentListViews().get(0) + .getCount()); + + // Click to export tracks(At least two tracks) to KML files. + gpxFilesNumber = EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length; + trackNumber = EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount(); + EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_save_all), true); + EndToEndTestUtils.SOLO + .clickOnText(String.format(activityMyTracks.getString(R.string.menu_save_format), + EndToEndTestUtils.KML.toUpperCase())); + EndToEndTestUtils.SOLO.waitForText(activityMyTracks + .getString(R.string.external_storage_save_success)); + EndToEndTestUtils + .getButtonOnScreen(activityMyTracks.getString(R.string.generic_ok), true, true); + + // Check export files. + assertEquals(gpxFilesNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.GPX).length); + assertEquals(trackNumber, EndToEndTestUtils.getExportedFiles(EndToEndTestUtils.KML).length); + } + + @Override + protected void tearDown() throws Exception { + EndToEndTestUtils.SOLO.finishOpenedActivities(); + super.tearDown(); + } + +} diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java index c614b418a..3d42117c6 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java @@ -136,7 +136,7 @@ public class BigTestUtils { } /** - * Unlocks and wake up the device. + * Unlocks and wakes up the device. */ public static void unlockAndWakeupDevice() { // The menu item of setting should be found if the screen is not locked.