From 19281e291945d7b359f137b36d4a2be1f36d4931 Mon Sep 17 00:00:00 2001 From: youtaol Date: Wed, 19 Dec 2012 09:47:21 +0800 Subject: [PATCH] Move method findAndClickMyLocation from GoToMyLocationTest to EndToEndTestUtils. --- .../endtoendtest/EndToEndTestUtils.java | 28 +++++++++++++++- .../endtoendtest/GoToMyLocationTest.java | 32 +------------------ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java index 8d3ee3818..0ef9dbf8a 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java @@ -300,7 +300,7 @@ public class EndToEndTestUtils { instrumentation.waitForIdleSync(); // Check the status of real phone. For emulator, we would fix GPS signal. if (!isEmulator) { - GoToMyLocationTest.findAndClickMyLocation(activityMyTracks); + EndToEndTestUtils.findAndClickMyLocation(activityMyTracks); hasGpsSingal = !SOLO.waitForText(NO_GPS_MESSAGE_PREFIX, 1, SHORT_WAIT_TIME); SOLO.goBack(); } @@ -974,4 +974,30 @@ public class EndToEndTestUtils { while (SOLO.waitForText(text, 1, VERY_SHORT_WAIT_TIME)) {} return; } + + /** + * Finds the My Location view and click it. + * + * @param activity + */ + public static void findAndClickMyLocation(Activity activity) { + createTrackIfEmpty(1, false); + sendGps(30); + + View myLocation = SOLO.getCurrentActivity() + .findViewById(R.id.map_my_location); + // Find the My Location button in another if null. + if (myLocation == null) { + ArrayList aa = SOLO.getCurrentImageButtons(); + for (ImageButton imageButton : aa) { + if (imageButton.getContentDescription() != null + && imageButton.getContentDescription().equals( + activity.getString(R.string.icon_my_location))) { + myLocation = imageButton; + break; + } + } + } + SOLO.clickOnView(myLocation); + } } \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoToMyLocationTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoToMyLocationTest.java index a06719ae3..30c5b0203 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoToMyLocationTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoToMyLocationTest.java @@ -19,13 +19,9 @@ import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.util.GoogleLocationUtils; import com.google.android.maps.mytracks.R; -import android.app.Activity; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; -import android.view.View; -import android.widget.ImageButton; -import java.util.ArrayList; /** * Tests the function of go to my location. @@ -53,7 +49,7 @@ public class GoToMyLocationTest extends ActivityInstrumentationTestCase2 aa = EndToEndTestUtils.SOLO.getCurrentImageButtons(); - for (ImageButton imageButton : aa) { - if (imageButton.getContentDescription() != null - && imageButton.getContentDescription().equals( - activity.getString(R.string.icon_my_location))) { - myLocation = imageButton; - break; - } - } - } - EndToEndTestUtils.SOLO.clickOnView(myLocation); - } - @Override protected void tearDown() throws Exception { EndToEndTestUtils.SOLO.finishOpenedActivities();