【问题标题】:Xamarin UITest "Unable to set fake location on iOS Simulator"Xamarin UITest“无法在 iOS 模拟器上设置假位置”
【发布时间】:2018-07-27 13:27:42
【问题描述】:

我正在使用 Xamarin.UITest 在 Android 和 iOS 上测试 Xamarin Forms 应用程序。由于应用程序依赖于 GPS 位置,我需要设置一个假位置。我这样做是使用

App.Device.SetLocation(latitude, longitude)

...其中latitudelongitude 是包含所需坐标的double 类型变量。

这在 Android 上运行良好,但在 iPhone 模拟器上失败,但出现以下异常:

SetUp : Xamarin.UITest.XDB.Exceptions.DeviceAgentException : Unable to set location

ExitCode: 4

        -d,--device-id  <device-identifier> iOS Simulator GUID or 40-digit physical device ID
    set-location <latitude,longitude>
Expected lat,lng: Got 48,135831,11,573423

我做了一些研究,并在 Xamarin 论坛上找到了一个帖子,上面说将假坐标四舍五入到小数点后仅 4 位可能会有所帮助,但它没有帮助。除此之外,我尝试对坐标进行硬编码并使用floats 而不是doubles,但都没有成功。

那里发生了什么,如何解决?

这是我的设置:

  • Xamarin.UITest 2.2.4 版
  • 在 iPhone 6 上运行 iOS 9.3 的 iOS 模拟器
  • 主机:运行 MacOS High Sierra 10.13.6 的 Mac mini

几个月前,同样的问题发生在以下设置中:

  • Xamarin.UITest 2.2.1 版
  • 在 iPhone X 上运行 iOS 11.2 的 iOS 模拟器
  • 主机:运行 MacOS High Sierra (10.13.3) 的 Mac Mini

当时,我只是不理会它,但现在是我需要修复的时候了。

【问题讨论】:

    标签: ios xamarin xamarin.forms xamarin.uitest


    【解决方案1】:

    Expected lat,lng: Got 48,135831,11,573423

    这似乎是一个错误,因为 Xamarin 在将这些双精度数发送到 simctl 时使用您的语言环境将它们转换为字符串(并且 simctl 期望基于小数点的字符串 or 带引号的小数和因此它正在解析那些是 4 个单独的数字)。

    在设置位置之前在您的测试代码中,将文化更改为en-US,如果需要,稍后将其设置回您的实际文化。

    这样的事情应该可以工作:

    var currentCulture = CultureInfo.DefaultThreadCurrentCulture;
    CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-US");"
    
    // do some location setting / testing
    
    CultureInfo.DefaultThreadCurrentCulture = currentCulture;
    

    【讨论】:

      猜你喜欢
      • 2014-11-10
      • 2016-02-28
      • 2013-11-12
      • 2016-08-13
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      相关资源
      最近更新 更多