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 3f7e63720..1edae4292 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 @@ -84,35 +84,19 @@ public class EndToEndTestUtils { private static final String MENUITEM_CLASSNAME = "com.android.internal.view.menu.IconMenuItemView"; // Following is some check strings in English and Chinese - private static final HashMap RELATIVE_START_TIME_POSTFIX_MULTILINGUAL = new HashMap(); - private static final HashMap KM_MULTILINGUAL = new HashMap(); - private static final HashMap MILE_MULTILINGUAL = new HashMap(); + private static final HashMap + RELATIVE_START_TIME_SUFFIX_MULTILINGUAL = new HashMap(); static { - RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.put("en", "mins ago"); - RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.put("de", "Minuten"); - RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.put("fr", "minute"); - RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.put("ar", "دقيقة"); - RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.put("zh", "分钟前"); - - KM_MULTILINGUAL.put("en", "km"); - KM_MULTILINGUAL.put("de", "km"); - KM_MULTILINGUAL.put("fr", "km"); - KM_MULTILINGUAL.put("ar", "كم"); - KM_MULTILINGUAL.put("zh", "公里"); - - MILE_MULTILINGUAL.put("en", "mi"); - MILE_MULTILINGUAL.put("de", "mi"); - MILE_MULTILINGUAL.put("fr", "mile"); - MILE_MULTILINGUAL.put("ar", "ميل"); - MILE_MULTILINGUAL.put("zh", "英里"); + RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("en", "mins ago"); + RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("de", "Minuten"); + RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("fr", "minute"); + RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("ar", "دقيقة"); + RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.put("zh", "分钟前"); } public static int emulatorPort = 5554; // usually 5554. public static String activityType = DEFAULT_ACTIVITY_TYPE; - public static String RELATIVE_START_TIME_POSTFIX = ""; - public static String KM = ""; - public static String MILE = ""; public static String trackName; public static String trackDescription; public static com.robotium.solo.Solo SOLO; @@ -129,7 +113,8 @@ public class EndToEndTestUtils { private static boolean isCheckedFirstLaunch = false; private static boolean isGooglePlayServicesLatest = true; - + private static String language; + private EndToEndTestUtils() {}; /** @@ -143,17 +128,7 @@ public class EndToEndTestUtils { .getResources().getConfiguration(); configuration.locale = locale; - String language = instrumentation.getContext().getResources().getConfiguration().locale - .getLanguage(); - if (RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.get(language) != null) { - RELATIVE_START_TIME_POSTFIX = RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.get(language); - KM = KM_MULTILINGUAL.get(language); - MILE = MILE_MULTILINGUAL.get(language); - } else { - RELATIVE_START_TIME_POSTFIX = RELATIVE_START_TIME_POSTFIX_MULTILINGUAL.get("en"); - KM = KM_MULTILINGUAL.get("en"); - MILE = MILE_MULTILINGUAL.get("en"); - } + language = instrumentation.getContext().getResources().getConfiguration().locale.getLanguage(); } /** @@ -347,11 +322,10 @@ public class EndToEndTestUtils { instrumentation.waitForIdleSync(); stopRecording(true); - instrumentation.waitForIdleSync(); if (showTrackList) { SOLO.goBack(); + instrumentation.waitForIdleSync(); } - instrumentation.waitForIdleSync(); } /** @@ -477,6 +451,8 @@ public class EndToEndTestUtils { enterTextAvoidSoftKeyBoard(2, trackDescription); SOLO.clickOnText(trackListActivity.getString(R.string.generic_save)); instrumentation.waitForIdleSync(); + } else { + instrumentation.waitForIdleSync(); } } } @@ -928,7 +904,7 @@ public class EndToEndTestUtils { * * @param activity */ - public static void findAndClickMyLocation(Activity activity) { + private static void findAndClickMyLocation(Activity activity) { createTrackIfEmpty(1, false); sendGps(30); @@ -948,4 +924,30 @@ public class EndToEndTestUtils { } SOLO.clickOnView(myLocation); } + + /** + * Gets the relative start time suffix. + */ + public static String getRelativeStartTimeSuffix() { + String value = RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.get(language); + return value != null ? value : RELATIVE_START_TIME_SUFFIX_MULTILINGUAL.get("en"); + } + + /** + * Changes to metric units. + */ + public static void changeToMetricUnits() { + EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), true); + EndToEndTestUtils.SOLO.clickOnText( + trackListActivity.getString(R.string.track_detail_stats_tab)); + Assert.assertTrue(EndToEndTestUtils.SOLO.waitForText( + trackListActivity.getString(R.string.settings_stats_units_title))); + + // Change the preferred units + EndToEndTestUtils.SOLO.clickOnText( + trackListActivity.getString(R.string.settings_stats_units_title)); + EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.unit_kilometer)); + EndToEndTestUtils.SOLO.goBack(); + EndToEndTestUtils.SOLO.goBack(); + } } \ No newline at end of file diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/CreateTrackTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/CreateTrackTest.java index 8897f6ec6..b69521ce0 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/CreateTrackTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/CreateTrackTest.java @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package com.google.android.apps.mytracks.endtoendtest.common; import com.google.android.apps.mytracks.TrackListActivity; @@ -21,18 +22,17 @@ import com.google.android.maps.mytracks.R; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; -import android.view.KeyEvent; import android.widget.ListView; /** - * Tests creating a track with markers, and editing and sending send a track. + * Tests creating new tracks. * * @author Youtao Liu */ public class CreateTrackTest extends ActivityInstrumentationTestCase2 { private Instrumentation instrumentation; - private TrackListActivity activityMyTracks; + private TrackListActivity trackListActivity; public CreateTrackTest() { super(TrackListActivity.class); @@ -42,176 +42,10 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2 0); - } else { - assertTrue(EndToEndTestUtils.SOLO.getCurrentViews(ListView.class).get(0).getCount() == 0); - } - EndToEndTestUtils.SOLO.goBack(); - - EndToEndTestUtils.stopRecording(true); } @Override @@ -219,4 +53,120 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2 0); + } + EndToEndTestUtils.SOLO.goBack(); + instrumentation.waitForIdleSync(); + + EndToEndTestUtils.stopRecording(true); + } + + /** + * Checks recording. + */ + private void checkRecording() { + if (EndToEndTestUtils.hasActionBar) { + // Check the title is Recording... + assertTrue(EndToEndTestUtils.SOLO.searchText( + trackListActivity.getString(R.string.generic_recording))); + } + } } \ No newline at end of file diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/EditTrackTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/EditTrackTest.java new file mode 100644 index 000000000..467edf73d --- /dev/null +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/EditTrackTest.java @@ -0,0 +1,112 @@ +/* + * 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.common; + +import com.google.android.apps.mytracks.TrackListActivity; +import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; +import com.google.android.maps.mytracks.R; + +import android.app.Instrumentation; +import android.test.ActivityInstrumentationTestCase2; +import android.view.KeyEvent; + +/** + * Tests editing a track. + * + * @author Youtao Liu + */ +public class EditTrackTest extends ActivityInstrumentationTestCase2 { + + private Instrumentation instrumentation; + private TrackListActivity trackListActivity; + + public EditTrackTest() { + super(TrackListActivity.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + instrumentation = getInstrumentation(); + trackListActivity = getActivity(); + EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); + } + + @Override + protected void tearDown() throws Exception { + EndToEndTestUtils.SOLO.finishOpenedActivities(); + super.tearDown(); + } + + /** + * Tests editing a track. + */ + public void testEditTrack() { + EndToEndTestUtils.deleteAllTracks(); + + EndToEndTestUtils.createSimpleTrack(1, false); + + // Click on the Edit menu item + EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_edit), true); + + // Rotate phone + EndToEndTestUtils.rotateCurrentActivity(); + EndToEndTestUtils.SOLO.waitForText(trackListActivity.getString(R.string.generic_save)); + + String newName = EndToEndTestUtils.TRACK_NAME_PREFIX + "_new" + System.currentTimeMillis(); + String newActivityType = EndToEndTestUtils.activityType; + String newDescription = "new_description_" + newName; + + // Clear name field + sendKeys(KeyEvent.KEYCODE_DEL); + // Enter new name + EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, newName); + + // Enter new activity type + EndToEndTestUtils.SOLO.clearEditText(1); + EndToEndTestUtils.enterTextAvoidSoftKeyBoard(1, newActivityType); + + // Enter new description + EndToEndTestUtils.SOLO.clearEditText(2); + EndToEndTestUtils.enterTextAvoidSoftKeyBoard(2, newDescription); + + // Change activity type using the activity picker + assertTrue(EndToEndTestUtils.SOLO.searchText(newActivityType)); + EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getCurrentActivity() + .findViewById(R.id.track_edit_activity_type_icon)); + EndToEndTestUtils.SOLO.waitForText( + trackListActivity.getString(R.string.track_edit_activity_type_hint)); + int walkingActivityTypeIndex = 1; + EndToEndTestUtils.SOLO.clickOnView(EndToEndTestUtils.SOLO.getImage(walkingActivityTypeIndex)); + EndToEndTestUtils.SOLO.clickOnButton(trackListActivity.getString(R.string.generic_ok)); + + // The activity type should be replaced by the walking activity type + assertFalse(EndToEndTestUtils.SOLO.searchText(newActivityType)); + assertTrue(EndToEndTestUtils.SOLO.searchText( + trackListActivity.getString(R.string.activity_type_walking))); + + // Save + EndToEndTestUtils.SOLO.clickOnButton(trackListActivity.getString(R.string.generic_save)); + instrumentation.waitForIdleSync(); + + // Go back to the TrackListActivity + EndToEndTestUtils.SOLO.goBack(); + instrumentation.waitForIdleSync(); + assertTrue(EndToEndTestUtils.SOLO.searchText(newName)); + assertTrue(EndToEndTestUtils.SOLO.searchText(newDescription)); + } +} \ No newline at end of file diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java index 6018e1f12..c8dcf1eba 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/ExportAllAndImportAllTest.java @@ -213,7 +213,7 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< * @param trackFileFormat the track file format */ private void testExportImportOne(TrackFileFormat trackFileFormat) { - changeToMetricUnits(); + EndToEndTestUtils.changeToMetricUnits(); showGradeElevation(); addTrackFromGpxFile(); @@ -619,24 +619,6 @@ public class ExportAllAndImportAllTest extends ActivityInstrumentationTestCase2< } } - /** - * Changes to metric units. - */ - private void changeToMetricUnits() { - EndToEndTestUtils.findMenuItem(trackListActivity.getString(R.string.menu_settings), true); - EndToEndTestUtils.SOLO.clickOnText( - trackListActivity.getString(R.string.track_detail_stats_tab)); - assertTrue(EndToEndTestUtils.SOLO.waitForText( - trackListActivity.getString(R.string.settings_stats_units_title))); - - // Change the preferred units - EndToEndTestUtils.SOLO.clickOnText( - trackListActivity.getString(R.string.settings_stats_units_title)); - EndToEndTestUtils.SOLO.clickOnText(trackListActivity.getString(R.string.unit_kilometer)); - EndToEndTestUtils.SOLO.goBack(); - EndToEndTestUtils.SOLO.goBack(); - } - /** * Shows grade elevation. */ diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/SettingTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/SettingTest.java index 088c7bc69..cae69ea67 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/SettingTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/SettingTest.java @@ -298,7 +298,6 @@ public class SettingTest extends ActivityInstrumentationTestCase2