DeviceService

Learn how to use BELLATRIX iOS DeviceService.

Example

[TestClass]
[IOS(Constants.IOSNativeAppPath,
    Constants.IOSDefaultVersion,
    Constants.IOSDefaultDeviceName,
    AppBehavior.RestartEveryTime)]
public class DeviceServiceTests : IOSTest
{
    [TestMethod]
    public void OrientationSetToLandscape_When_CallRotateWithLandscape()
    {
        App.DeviceService.Rotate(ScreenOrientation.Landscape);

        Assert.AreEqual(ScreenOrientation.Landscape, App.DeviceService.Orientation);

        App.DeviceService.Rotate(ScreenOrientation.Portrait);
    }

    [TestMethod]
    public void CorrectTimeReturned_When_CallDeviceTime()
    {
        BA.DateTimeAssert.AreEqual(DateTime.Now, App.DeviceService.DeviceTime, BA.DateTimeDeltaType.Minutes, 5);
    }

    [TestMethod]
    public void DeviceIsLockedTrue_When_CallLock()
    {
        App.DeviceService.Lock(1);
    }

    [TestMethod]
    public void TestShakeDevice()
    {
        App.DeviceService.ShakeDevice();
    }
}

Explanations

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

App.DeviceService.Rotate(ScreenOrientation.Landscape);

Rotates the device horizontally.

Assert.AreEqual(ScreenOrientation.Landscape, App.DeviceService.Orientation);

Gets the current device orientation.

BA.DateTimeAssert.AreEqual(DateTime.Now, App.DeviceService.DeviceTime, BA.DateTimeDeltaType.Minutes, 5);

Asserts current device time.

App.DeviceService.Lock(1);
App.DeviceService.ShakeDevice();

Shakes the device.