From 7b025443c124c51902429654d83f851c5c8fd046 Mon Sep 17 00:00:00 2001 From: youtaol Date: Tue, 4 Sep 2012 15:04:11 +0800 Subject: [PATCH] Add checks about the status of recording, pause and not in recording. Add method findTextView and sleep to help current and following tests. --- .../mytracks/endtoendtest/DeleteTest.java | 5 +- .../endtoendtest/EndToEndTestUtils.java | 37 ++++++- .../endtoendtest/PauseRecordingTest.java | 100 ++++++++++++++---- .../mytracks/endtoendtest/SettingTest.java | 2 +- 4 files changed, 117 insertions(+), 27 deletions(-) diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java index 33fc39eb7..db1052be6 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/DeleteTest.java @@ -105,16 +105,15 @@ public class DeleteTest extends ActivityInstrumentationTestCase2 textViews = SOLO.getCurrentTextViews(parent); for (TextView textView : textViews) { String text = (String) textView.getText(); @@ -742,6 +742,26 @@ public class EndToEndTestUtils { } return null; } + + /** + * Finds a displayed text view with specified text. + * + * @param findText text to find + * @return the text view, null means can not find it + */ + static TextView findTextView(String findText) { + ArrayList allViews = SOLO.getViews(); + for (View view : allViews) { + if (view instanceof TextView) { + TextView textView = (TextView) view; + String text = (String) textView.getText(); + if (textView.isShown() && text.endsWith(findText)) { + return textView; + } + } + } + return null; + } /** * Gets the ChartView. @@ -788,5 +808,18 @@ public class EndToEndTestUtils { imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); SOLO.enterText(editText, text); } + + /** + * Waits n milliseconds. + * + * @param milliseconds time to sleep + */ + public static void sleep(long milliseconds) { + try { + Thread.sleep(milliseconds); + } catch (InterruptedException e) { + Log.e(EndToEndTestUtils.LOG_TAG, "Unable to sleep " + milliseconds, e); + } + } } \ No newline at end of file diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/PauseRecordingTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/PauseRecordingTest.java index a0671f3d1..68be87e87 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/PauseRecordingTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/PauseRecordingTest.java @@ -19,12 +19,14 @@ import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.services.TrackRecordingService; +import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.maps.mytracks.R; import android.annotation.TargetApi; import android.app.Instrumentation; import android.location.Location; import android.test.ActivityInstrumentationTestCase2; +import android.widget.TextView; /** * Tests the pause and resume of recording. @@ -55,21 +57,22 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2