Device Service

Learn how to use BELLATRIX android device service.

Example

public class DeviceServiceTests extends AndroidTest {
    @Test
    public void orientationSetToLandscape_When_CallRotateWithLandscape() {
        app().device().rotate(ScreenOrientation.LANDSCAPE);

        Assert.assertEquals(app().device().getScreenOrientation(), ScreenOrientation.LANDSCAPE);
    }

    @Test
    public void correctTimeReturned_When_CallDeviceTime() {
        Assert.assertEquals(app().device().getDeviceTime().toEpochSecond(ZoneOffset.UTC), LocalDateTime.now().toEpochSecond(ZoneOffset.UTC), 5);
    }

    @Test
    public void deviceIsLockedFalse_When_DeviceIsUnlocked() {
        app().device().unlock();

        Assert.assertTrue(app().device().isLocked());
    }

    @Test
    public void deviceIsLockedTrue_When_CallLock() {
        app().device().lock();

        Assert.assertTrue(app().device().isLocked());
    }

    @Test
    public void testTurnOnLocationService() {
        app().device().turnOnLocationService();
    }

    @Test
    public void testOpenNotifications() {
        app().device().openNotifications();
    }
}

Explanations

BELLATRIX gives you an interface to most common operations for controlling the device through the device method.

app().device().rotate(ScreenOrientation.LANDSCAPE);

Rotates the device horizontally.

Assert.assertEquals(app().device().getScreenOrientation(), ScreenOrientation.LANDSCAPE);

Gets the current device orientation.

Assert.assertEquals(app().device().getDeviceTime().toEpochSecond(ZoneOffset.UTC), LocalDateTime.now().toEpochSecond(ZoneOffset.UTC), 5);

Asserts current device time.

app().device().unlock();

Unlocks the device.

Assert.assertTrue(app().device().isLocked());

Checks if the device is locked or not.

app().device().lock();

Locks the device.

app().device().turnOnLocationService();

Turns on the location service.

app().device().openNotifications();

Opens notifications.