From b052c34e76250cb00ecc8e63bbc2243242f85704 Mon Sep 17 00:00:00 2001 From: youtaol Date: Fri, 27 Jul 2012 16:51:18 +0800 Subject: [PATCH] Make test can run on Android 4.1. Initialize the status of GPS signal and then use it during test. Create a common method to enter text which can hides soft keyboard. --- .../endtoendtest/CreateAndSendTrackTest.java | 30 +++--- .../endtoendtest/EndToEndTestUtils.java | 99 ++++++++++++------- .../endtoendtest/GoToMyLocationTest.java | 30 +++--- .../mytracks/endtoendtest/MenuItemsTest.java | 6 +- .../mytracks/endtoendtest/SettingTest.java | 4 +- 5 files changed, 95 insertions(+), 74 deletions(-) diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java index 4d16814aa..323430860 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java @@ -23,7 +23,6 @@ import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; import android.view.KeyEvent; import android.widget.CheckBox; -import android.widget.EditText; import java.util.ArrayList; @@ -166,18 +165,10 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2 editTexts = EndToEndTestUtils.SOLO.getCurrentEditTexts(); - - EndToEndTestUtils.SOLO.enterText(editTexts.get(0), newTrackName); - EndToEndTestUtils.SOLO.enterText(editTexts.get(1), newType); - // In landscape, there are only two visible edit texts. - if (editTexts.size() > 2) { - EndToEndTestUtils.SOLO.enterText(editTexts.get(2), newDesc); - } else { - EndToEndTestUtils.SOLO.scrollDown(); - editTexts = EndToEndTestUtils.SOLO.getCurrentEditTexts(); - EndToEndTestUtils.SOLO.enterText(editTexts.get(editTexts.size() - 1), newDesc); - } + + EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, newTrackName); + EndToEndTestUtils.enterTextAvoidSoftKeyBoard(1, newType); + EndToEndTestUtils.enterTextAvoidSoftKeyBoard(2, newDesc); EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_save)); instrumentation.waitForIdleSync(); // Go back to track list. @@ -289,7 +280,11 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2 0); + if (EndToEndTestUtils.hasGPSSingal) { + assertTrue(EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount() > 0); + } else { + assertTrue(EndToEndTestUtils.SOLO.getCurrentListViews().get(0).getCount() == 0); + } EndToEndTestUtils.SOLO.goBack(); EndToEndTestUtils.stopRecording(true); @@ -304,11 +299,12 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2 currentButtons = SOLO.getCurrentButtons(); - for (Button button : currentButtons) { - String title = (String) button.getText(); - if (title.equalsIgnoreCase(buttonName)) { - if(isClick) { - SOLO.clickOnView(button); + + if (hasActionBar) { + ArrayList allViews = SOLO.getViews(); + for (View view : allViews) { + String className = view.getClass().getName(); + if(className.indexOf("ActionMenuItemView") > 0) { + String menuItemNameString = view.getContentDescription().toString(); + if(menuItemNameString.equalsIgnoreCase(buttonName)) { + button = view; + break; + } } - return button; } } - return null; + + ArrayList