Xamarin UITest "Unable to set fake location on iOS Simulator"

Xamarin UITest "Unable to set fake location on iOS Simulator"

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

执行此操作
App.Device.SetLocation(latitude, longitude)

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

这在 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 但两种尝试均无效。

这是怎么回事,如何解决?

这是我的设置:

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

当时我就不管了,现在是我该修的时候了。

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

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

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

像这样的东西应该可以工作:

var currentCulture = CultureInfo.DefaultThreadCurrentCulture;
CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("en-US");"

// do some location setting / testing

CultureInfo.DefaultThreadCurrentCulture = currentCulture;