【问题标题】:Xamarin UITest - determine if device is Phone or Tablet for Android?Xamarin UITest - 确定设备是适用于 Android 的手机还是平板电脑?
【发布时间】:2017-01-23 14:02:27
【问题描述】:

有没有办法确定我正在运行测试的 Android 设备是手机还是平板电脑?从 Android 开发的角​​度找到了关于这个主题的各种答案,但我只是在开发测试并从 Xamarin.UITest 中寻找一些可以告诉我这一点的方法。对于 iOS,有一个像 app.Device.IsPhone 这样的内置方法,但我似乎找不到适用于 Android 的类似方法。

有什么想法吗?

【问题讨论】:

标签: xamarin.ios xamarin.android xamarin-test-cloud xamarin.uitest


【解决方案1】:

我在测试中这样做的方式是检查设备的大小,请参见下面的代码:

public bool DeviceIsTablet()
    {
        var screen = app.Query(x => x.Id("content"));
        var height = screen.FirstOrDefault().Rect.Height;
        var width = screen.FirstOrDefault().Rect.Width;
        if (width < 1600 || height > 1850)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

【讨论】:

  • Mina Fawzy 的正确数字是多少?
猜你喜欢
  • 1970-01-01
  • 2016-11-09
  • 2012-07-05
  • 1970-01-01
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
  • 2014-12-26
相关资源
最近更新 更多