|
32 | 32 | import static com.google.common.truth.Truth.assertThat;
|
33 | 33 | import static org.hamcrest.MatcherAssert.assertThat;
|
34 | 34 | import static org.hamcrest.Matchers.allOf;
|
35 |
| -import static org.hamcrest.Matchers.any; |
36 | 35 | import static org.hamcrest.Matchers.contains;
|
37 | 36 | import static org.hamcrest.Matchers.containsString;
|
38 | 37 | import static org.hamcrest.Matchers.hasValue;
|
|
58 | 57 | import androidx.test.ui.app.KeyboardTestActivity;
|
59 | 58 | import androidx.test.ui.app.MainActivity;
|
60 | 59 | import androidx.test.ui.app.R;
|
61 |
| -import androidx.test.ui.app.SendActivity; |
62 | 60 | import java.util.Map;
|
63 | 61 | import java.util.concurrent.CountDownLatch;
|
64 | 62 | import java.util.concurrent.atomic.AtomicBoolean;
|
@@ -262,45 +260,26 @@ public void openOverflowInActionMode() {
|
262 | 260 | }
|
263 | 261 |
|
264 | 262 | @Test
|
265 |
| - public void closeSoftKeyboard() { |
266 |
| - onData(allOf(instanceOf(Map.class), hasValue(SendActivity.class.getSimpleName()))) |
| 263 | + public void closeSoftKeyboard() throws InterruptedException { |
| 264 | + onData(allOf(instanceOf(Map.class), hasValue(KeyboardTestActivity.class.getSimpleName()))) |
267 | 265 | .perform(click());
|
| 266 | + // click on the edit text which bring the soft keyboard up |
| 267 | + onView(withId(R.id.editTextUserInput)).perform(typeText("Espresso")); |
268 | 268 |
|
269 |
| - onView(withId(R.id.enter_data_edit_text)) |
270 |
| - .perform( |
271 |
| - new ViewAction() { |
272 |
| - @Override |
273 |
| - public Matcher<View> getConstraints() { |
274 |
| - return any(View.class); |
275 |
| - } |
276 |
| - |
| 269 | + onView(withId(R.id.editTextUserInput)) |
| 270 | + .check( |
| 271 | + new ViewAssertion() { |
277 | 272 | @Override
|
278 |
| - public void perform(UiController uiController, View view) { |
279 |
| - // This doesn't do anything if hardware keyboard is present - that is, soft keyboard |
280 |
| - // is _not_ present. Whether it's present or not can be verified under the following |
281 |
| - // device settings: Settings > Language & Input > Under Keyboard and input method |
| 273 | + public void check(View view, NoMatchingViewException noViewFoundException) { |
282 | 274 | InputMethodManager imm =
|
283 | 275 | (InputMethodManager)
|
284 |
| - getInstrumentation() |
285 |
| - .getTargetContext() |
286 |
| - .getSystemService(Context.INPUT_METHOD_SERVICE); |
287 |
| - imm.showSoftInput(view, 0); |
288 |
| - uiController.loopMainThreadUntilIdle(); |
289 |
| - } |
290 |
| - |
291 |
| - @Override |
292 |
| - public String getDescription() { |
293 |
| - return "show soft input"; |
| 276 | + view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); |
| 277 | + assertTrue(imm.isActive(view)); |
294 | 278 | }
|
295 | 279 | });
|
296 | 280 |
|
297 |
| - onView(withId(R.id.enter_data_edit_text)).perform(ViewActions.closeSoftKeyboard()); |
| 281 | + onView(withId(R.id.editTextUserInput)).perform(ViewActions.closeSoftKeyboard()); |
298 | 282 |
|
299 |
| - assertThat(tracer.getSpans()) |
300 |
| - .containsAtLeast( |
301 |
| - "beginSpan: Espresso.perform(show soft input, view.getId() is <ID>)", |
302 |
| - "+-endSpan: Espresso.perform(show soft input, view.getId() is <ID>)") |
303 |
| - .inOrder(); |
304 | 283 | assertThat(tracer.getSpans())
|
305 | 284 | .containsAtLeast(
|
306 | 285 | "beginSpan: Espresso.perform(CloseKeyboardAction, view.getId() is <ID>)",
|
|
0 commit comments