forked from upstream-mirrors/OpenTracks
Change showMoreMenuItem() to showMenuIten() and make the logic to find menu right and clear. Fix issues when run on emulator 2.3.3.
This commit is contained in:
+60
-31
@@ -312,6 +312,7 @@ public class EndToEndTestUtils {
|
||||
if (EndToEndTestUtils.isTrackListEmpty(!showTrackList)) {
|
||||
// Create a simple track.
|
||||
EndToEndTestUtils.createSimpleTrack(gpsNumber);
|
||||
instrumentation.waitForIdleSync();
|
||||
if (showTrackList) {
|
||||
EndToEndTestUtils.SOLO.goBack();
|
||||
}
|
||||
@@ -331,7 +332,7 @@ public class EndToEndTestUtils {
|
||||
}
|
||||
SOLO.clickOnView(startButton);
|
||||
} else {
|
||||
showMoreMenuItem(0);
|
||||
showMenuItem();
|
||||
if (!SOLO.searchText(activityMytracks.getString(R.string.menu_record_track))) {
|
||||
// Check if in TrackDetailActivity.
|
||||
if (SOLO.searchText(activityMytracks.getString(R.string.menu_play))) {
|
||||
@@ -339,7 +340,7 @@ public class EndToEndTestUtils {
|
||||
} else {
|
||||
// In case a track is recording.
|
||||
stopRecording(true);
|
||||
showMoreMenuItem(0);
|
||||
showMenuItem();
|
||||
}
|
||||
}
|
||||
instrumentation.waitForIdleSync();
|
||||
@@ -358,7 +359,7 @@ public class EndToEndTestUtils {
|
||||
return getButtonOnScreen(activityMytracks
|
||||
.getString(R.string.menu_record_track), false, false) == null;
|
||||
}
|
||||
showMoreMenuItem(0);
|
||||
showMenuItem();
|
||||
if (SOLO.searchText(activityMytracks.getString(R.string.menu_record_track))
|
||||
|| SOLO.searchText(activityMytracks.getString(R.string.menu_play))) {
|
||||
SOLO.goBack();
|
||||
@@ -377,7 +378,7 @@ public class EndToEndTestUtils {
|
||||
if (hasActionBar) {
|
||||
getButtonOnScreen(activityMytracks.getString(R.string.menu_stop_recording), false, true);
|
||||
} else {
|
||||
showMoreMenuItem(0);
|
||||
showMenuItem();
|
||||
instrumentation.waitForIdleSync();
|
||||
SOLO.clickOnText(activityMytracks.getString(R.string.menu_stop_recording));
|
||||
}
|
||||
@@ -494,7 +495,7 @@ public class EndToEndTestUtils {
|
||||
if (startButton != null || stopButton != null) {
|
||||
hasActionBar = true;
|
||||
} else {
|
||||
showMoreMenuItem(0);
|
||||
showMenuItem();
|
||||
if (SOLO.searchText(activityMytracks.getString(R.string.menu_record_track))
|
||||
|| SOLO.searchText(activityMytracks.getString(R.string.menu_stop_recording))) {
|
||||
hasActionBar = false;
|
||||
@@ -518,12 +519,14 @@ public class EndToEndTestUtils {
|
||||
* Rotates all activities.
|
||||
*/
|
||||
static void rotateAllActivities() {
|
||||
ArrayList<Activity> allActivities = SOLO.getAllOpenedActivities();
|
||||
for (Activity activity : allActivities) {
|
||||
EndToEndTestUtils.rotateActivity(activity);
|
||||
if(hasActionBar) {
|
||||
ArrayList<Activity> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user