/** * Check that the soft keyboard is closed. * * > Warning: Espresso don't wait for keyboard open/close actions so this method have a fixed delay to avoid flaky tests. * You can adjust the delay by changing EspDevice.DELAY_TO_CHANGE_KEYBOARD_STATE * * @since Espresso Macchiato 0.2 */ public void assertSoftKeyboardIsClosed() { assertSoftKeyboardIsOpen(false); }
/** * Create new element instance. * * @return New Instance for actions and assertions. * @since Espresso Macchiato 0.2 */ public static EspDevice root() { return new EspDevice(); }
@Test public void testRotate() { espDevice.assertOrientationIsPortrait(); espDevice.rotateToLandscape(); espDevice.assertOrientationIsLandscape(); espDevice.rotateToPortrait(); espDevice.assertOrientationIsPortrait(); }
@Test public void testRotateOnOrientationFixedActivity() { espDevice.assertOrientationIsLandscape(); espDevice.rotateToLandscape(); espDevice.assertOrientationIsLandscape(); } }
@Test public void testCloseSoftKeyboard() { givenEditTextToOpenSoftKeyboard(); espDevice.assertSoftKeyboardIsClosed(); espEditText.click(); espDevice.assertSoftKeyboardIsOpen(); espDevice.closeSoftKeyboard(); espDevice.assertSoftKeyboardIsClosed(); }
@Test @Ignore("change orientation works only for current activity but not following activities") public void testKeepRotation() { espDevice.assertOrientationIsPortrait(); espDevice.rotateToLandscape(); espDevice.assertOrientationIsLandscape(); getActivity().startActivity(new Intent(getActivity(), LongListActivity.class)); espDevice.assertOrientationIsLandscape(); }
@After public void reset() { espDevice.rotateToPortrait(); espDevice.closeSoftKeyboard(); }
@Test public void testAssertOrientationIsPortraitFailure() { exception.expect(AssertionFailedError.class); exception.expectMessage(is("expected device orientation PORTRAIT but was LANDSCAPE")); espDevice.rotateToLandscape(); espDevice.assertOrientationIsPortrait(); }
@Test public void testAssertOrientationIsLandscapeFailure() { exception.expect(AssertionFailedError.class); exception.expectMessage(is("expected device orientation LANDSCAPE but was PORTRAIT")); espDevice.rotateToPortrait(); espDevice.assertOrientationIsLandscape(); }
@Test public void testDummyLauncher() { EspPage.byId(EspDummyLauncherActivity.rootLayout).assertIsDisplayedOnScreen(); // test start method EspDummyLauncherActivity activity = getActivity(); activity.setStartIntent(BaseActivity.class); activity.start(); EspPage.byId(BaseActivity.rootLayout).assertIsDisplayedOnScreen(); EspDevice.root().clickBackButton(); EspPage.byId(EspDummyLauncherActivity.rootLayout).assertIsDisplayedOnScreen(); // test click action EspButton.byId(EspDummyLauncherActivity.buttonId).click(); EspPage.byId(BaseActivity.rootLayout).assertIsDisplayedOnScreen(); }
@Test public void testIsScreenSizeAtMost() { assertTrue(espDevice.isScreenSizeAtMost(currentScreenSize)); assertTrue(espDevice.isScreenSizeAtMost(currentScreenSize + 1)); assertFalse(espDevice.isScreenSizeAtMost(currentScreenSize - 1)); }
@Test public void testIsScreenSizeAtLeast() { assertTrue(espDevice.isScreenSizeAtLeast(currentScreenSize)); assertTrue(espDevice.isScreenSizeAtLeast(currentScreenSize - 1)); assertFalse(espDevice.isScreenSizeAtLeast(currentScreenSize + 1)); }
@Test public void testIsScreenSizeEqualTo() { assertTrue(espDevice.isScreenSizeEqualTo(currentScreenSize)); assertFalse(espDevice.isScreenSizeEqualTo(currentScreenSize + 1)); }
@Test public void testAssertSoftKeyboardIsClosedFailure() { exception.expect(AssertionFailedError.class); exception.expectMessage(containsString("Keyboard should be closed.")); exception.expectMessage(containsString("Expected: is <true>")); exception.expectMessage(containsString("Got: <false>")); givenEditTextToOpenSoftKeyboard(); // other test works and difference is this extra check for initial closed. espDevice.assertSoftKeyboardIsClosed(); espEditText.click(); espDevice.assertSoftKeyboardIsClosed(); }
@Test public void testClickBackButton() { givenButtonToStartNextPage(); startPage.assertIsVisible(); espButton.click(); nextPage.assertIsVisible(); espDevice.clickBackButton(); startPage.assertIsVisible(); }
@Test public void testRotateWithDialog() { addDialog(new AlertDialog.Builder(getActivity())); espDevice.rotateToLandscape(); espDevice.assertOrientationIsLandscape(); }
/** * Check that the soft keyboard is open. * * For emulator disable the hardware keyboard support (hw.keyboard=no) or soft keyboard will never be shown. * * > Warning: Espresso don't wait for keyboard open/close actions so this method have a fixed delay to avoid flaky tests. * You can adjust the delay by changing EspDevice.DELAY_TO_CHANGE_KEYBOARD_STATE * * @since Espresso Macchiato 0.2 */ public void assertSoftKeyboardIsOpen() { assertSoftKeyboardIsOpen(true); }
@Test public void testAssertSoftKeyboardIsOpenFailure() { exception.expect(AssertionFailedError.class); exception.expectMessage(containsString("Keyboard should be open.")); exception.expectMessage(containsString("Expected: is <true>")); exception.expectMessage(containsString("Got: <false>")); espDevice.assertSoftKeyboardIsOpen(); }