public class EspDevice
extends java.lang.Object
Actions and assertions more related to a device.
| Modifier and Type | Field and Description |
|---|---|
static int |
DELAY_TO_CHANGE_KEYBOARD_STATE
Delay to wait before keyboard state is checked.
|
| Constructor and Description |
|---|
EspDevice() |
| Modifier and Type | Method and Description |
|---|---|
void |
assertOrientationIsLandscape()
Check that activity orientation is landscape.
|
void |
assertOrientationIsPortrait()
Check that activity orientation is portrait.
|
void |
assertSoftKeyboardIsClosed()
Check that the soft keyboard is closed.
|
void |
assertSoftKeyboardIsOpen()
Check that the soft keyboard is open.
|
void |
clickBackButton()
Click androids back button.
|
void |
closeSoftKeyboard()
Close the soft keyboard.
|
boolean |
isScreenSizeAtLeast(int screenSize)
Compares the current device screen size to the size given as parameter.
|
boolean |
isScreenSizeAtMost(int screenSize)
Compares the current device screen size to the size given as parameter.
|
boolean |
isScreenSizeEqualTo(int screenSize)
Compares the current device screen size to the size given as parameter.
|
static EspDevice |
root()
Create new element instance.
|
void |
rotateToLandscape()
Rotate screen to landscape.
|
void |
rotateToPortrait()
Rotate screen to portrait.
|
public static int DELAY_TO_CHANGE_KEYBOARD_STATE
Delay to wait before keyboard state is checked.
Waiting less than 4000ms was not enough for emulator instance on circle ci
public static EspDevice root()
Create new element instance.
public void clickBackButton()
Click androids back button.
Perform back button click so that the onBackPressed() method is called for the current activity. This is not the up button from an ActionBar.
Warning: When you back press on your root activity then your application becomes closed. Closing the application let current and all following tests fail. You can avoid closing your application with the Dummy Launcher concept.
public void rotateToPortrait()
Rotate screen to portrait.
Rotate the device to portrait mode. Waits until device has expected state to avoid flaky tests. Orientation is only changed if activity does not specify android:screenOrientation.
public void rotateToLandscape()
Rotate screen to landscape.
Rotate the device to landscape mode. Waits until device has expected state to avoid flaky tests. Orientation is only changed if activity does not specify android:screenOrientation.
public void assertOrientationIsPortrait()
Check that activity orientation is portrait.
public void assertOrientationIsLandscape()
Check that activity orientation is landscape.
public boolean isScreenSizeEqualTo(int screenSize)
Compares the current device screen size to the size given as parameter. The method will only return true if and only if the screen size is an exact match. For example a large tablet is XLARGE but not LARGE.
screenSize - SCREENLAYOUT_SIZE constant from android.content.res.Configuration for example Configuration.SCREENLAYOUT_SIZE_XLARGEpublic boolean isScreenSizeAtLeast(int screenSize)
Compares the current device screen size to the size given as parameter. The method will return true if the actual screen size is equal to or greater than the given screen size.
screenSize - SCREENLAYOUT_SIZE constant from android.content.res.Configuration for example Configuration.SCREENLAYOUT_SIZE_XLARGEpublic boolean isScreenSizeAtMost(int screenSize)
Compares the current device screen size to the size given as parameter. The method will return true if the actual screen size is equal to or smaller than the given screen size.
screenSize - SCREENLAYOUT_SIZE constant from android.content.res.Configuration for example Configuration.SCREENLAYOUT_SIZE_XLARGEpublic void closeSoftKeyboard()
Close the soft keyboard.
Its recommend to close the soft keyboard after tests run which could open it. Opened keyboards are sometimes not closed between tests and may result in flaky tests.
Warning: Close and open soft keyboard may take some time and Espresso don’t wait for finish it. Remember this if you have flaky tests with not displayed elements
public void assertSoftKeyboardIsOpen()
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
public void assertSoftKeyboardIsClosed()
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