Skip to content

Commit

Permalink
Add retries to Action Bar opening in test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revan Sopher committed May 30, 2018
1 parent 6c146bf commit 07085d7
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@
getById("button_done").clickAndWaitForNewWindow(TIMEOUT);

// Add random items
device.waitForIdle(TIMEOUT);
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
UiObject addItems = device.findObject(new UiSelector().textContains("Add Random Items"));
addItems.waitForExists(TIMEOUT);
addItems.click();
getActionBarItem(new UiSelector().textContains("Add Random Items"), TIMEOUT).click();
device.waitForIdle(TIMEOUT);

// Click on the first restaurant
Expand Down Expand Up @@ -96,4 +92,19 @@ private void closeKeyboard() {
}
}
}

private UiObject getActionBarItem(UiSelector selector, long timeout) throws InterruptedException {
final long STEP_TIMEOUT = 5000;
UiObject item = device.findObject(selector);

for (long i = 0; i < timeout; i += STEP_TIMEOUT) {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());

if (item.waitForExists(STEP_TIMEOUT)) {
break;
}
}

return item;
}
}

0 comments on commit 07085d7

Please sign in to comment.