From 56663c53a48f173b66186e4b372a4f3049d9ebae Mon Sep 17 00:00:00 2001 From: youtaol Date: Tue, 17 Jul 2012 14:14:19 +0800 Subject: [PATCH] Change showMoreMenuItem() to showMenuIten() and make the logic to find menu right and clear. Fix issues when run on emulator 2.3.3. --- .../endtoendtest/CreateAndSendTrackTest.java | 4 +- .../endtoendtest/EndToEndTestUtils.java | 91 ++++++++++++------- .../endtoendtest/GoToMyLocationTest.java | 18 +++- .../apps/mytracks/endtoendtest/ViewsTest.java | 48 +++++----- 4 files changed, 101 insertions(+), 60 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 acf82ac7e..0296806bf 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/CreateAndSendTrackTest.java @@ -117,8 +117,10 @@ public class CreateAndSendTrackTest extends ActivityInstrumentationTestCase2 allActivities = SOLO.getAllOpenedActivities(); - for (Activity activity : allActivities) { - EndToEndTestUtils.rotateActivity(activity); + if(hasActionBar) { + ArrayList allActivities = SOLO.getAllOpenedActivities(); + for (Activity activity : allActivities) { + EndToEndTestUtils.rotateActivity(activity); + } + + instrumentation.waitForIdleSync(); } - - instrumentation.waitForIdleSync(); } /** @@ -535,35 +538,54 @@ public class EndToEndTestUtils { */ static boolean findMenuItem(String menuName, boolean click) { boolean findResult = false; - - // Firstly find in action bar. - Button button = getButtonOnScreen(menuName, false, false); - if (button != null) { - findResult = true; - if (click) { - SOLO.clickOnView(button); - instrumentation.waitForIdleSync(); + boolean isMoreMenuOpened = false; + + // ICS phone. + if(hasActionBar) { + // Firstly find in action bar. + Button button = getButtonOnScreen(menuName, false, false); + if (button != null) { + findResult = true; + if (click) { + SOLO.clickOnView(button); + instrumentation.waitForIdleSync(); + } + return findResult; } - return findResult; - } - - showMoreMenuItem(0); - if (SOLO.searchText(menuName)) { - findResult = true; - } else if (SOLO.searchText(MENU_MORE)) { - SOLO.clickOnText(MENU_MORE); + showMenuItem(); findResult = SOLO.searchText(menuName); + } else { + // Non-ICS phone. + SOLO.sendKey(KeyEvent.KEYCODE_MENU); + if (SOLO.searchText(menuName)) { + findResult = true; + } else if (SOLO.searchText(MENU_MORE)) { + SOLO.clickOnText(MENU_MORE); + findResult = SOLO.searchText(menuName); + isMoreMenuOpened = true; + } } - + if (findResult && click) { SOLO.clickOnText(menuName); instrumentation.waitForIdleSync(); } else { + // Quit more menu list if opened. + if (isMoreMenuOpened) { + SOLO.goBack(); + } + // Quit menu list. SOLO.goBack(); } return findResult; } - + + /** + * Show menu item list. + */ + public static void showMenuItem() { + showMenuItem(0); + } /** * Gets more menu items operation is different for different Android OS. When * get overflow button view on action, it usually be able to click. But in @@ -572,22 +594,29 @@ public class EndToEndTestUtils { * * @param depth control the depth of recursion to prevent dead circulation */ - public static void showMoreMenuItem(int depth) { + private static void showMenuItem(int depth) { + // ICS phone. if (hasActionBar) { instrumentation.waitForIdleSync(); View moreButton = getMoreOptionView(); + // ICS phone without menu key. if (moreButton != null) { try { SOLO.clickOnView(moreButton); } catch (Throwable e) { if (depth < 5 && e.getMessage().indexOf("Click can not be completed") > -1) { - showMoreMenuItem(depth++); + showMenuItem(depth++); } } return; + } else { + // ICS phone with menu key. + SOLO.sendKey(KeyEvent.KEYCODE_MENU); } + } else { + // Non-ICS phone with menu key. + SOLO.sendKey(KeyEvent.KEYCODE_MENU); } - SOLO.sendKey(KeyEvent.KEYCODE_MENU); } /** 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 38ef84971..c6b89416a 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoToMyLocationTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/GoToMyLocationTest.java @@ -22,6 +22,9 @@ import android.annotation.TargetApi; 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. @@ -55,10 +58,23 @@ public class GoToMyLocationTest extends ActivityInstrumentationTestCase2 aa = EndToEndTestUtils.SOLO.getCurrentImageButtons(); + for (ImageButton imageButton : aa) { + if (imageButton.getContentDescription() != null + && imageButton.getContentDescription().equals( + activityMyTracks.getString(R.string.icon_my_location))) { + myLocation = imageButton; + break; + } + } + } EndToEndTestUtils.SOLO.clickOnView(myLocation); if (EndToEndTestUtils.isEmulator) { EndToEndTestUtils.SOLO.waitForText( - activityMyTracks.getString(R.string.my_location_no_location), 1, EndToEndTestUtils.SHORT_WAIT_TIME); + activityMyTracks.getString(R.string.my_location_no_location), 1, + EndToEndTestUtils.SHORT_WAIT_TIME); } else { // TODO How to verify the location is shown on the map. } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/ViewsTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/ViewsTest.java index 7b451e0f3..19fb7303d 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/ViewsTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/endtoendtest/ViewsTest.java @@ -23,7 +23,6 @@ import com.google.android.maps.mytracks.R; import android.annotation.TargetApi; import android.app.Instrumentation; import android.test.ActivityInstrumentationTestCase2; -import android.view.KeyEvent; import android.view.View; import java.util.ArrayList; @@ -57,38 +56,33 @@ public class ViewsTest extends ActivityInstrumentationTestCase2