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)
...其中 latitude
和 longitude
是包含所需坐标的双精度类型的变量。
这在 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 位数字,但它没有帮助。除此之外,我尝试对坐标进行硬编码并使用 float
s 而不是 double
s 但两种尝试均无效。
这是怎么回事,如何解决?
这是我的设置:
- Xamarin.UITest 版本 2.2.4
- iOS 模拟器 运行 iOS 9.3 on an iPhone 6
- 主机:Macmini 运行MacOS High Sierra 10.13.6
同样的问题在几个月前使用以下设置发生:
- Xamarin.UITest 版本 2.2.1
- iOS 模拟器 运行 iOS 11.2 在 iPhone X
上
- 主机:Mac Mini 运行 MacOS High Sierra (10.13.3)
当时我就不管了,现在是我该修的时候了。
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;
我正在 Android 和 iOS 上使用 Xamarin.UITest 测试 Xamarin Forms 应用程序。由于应用程序依赖于 GPS 位置,因此我需要设置一个假位置。我使用
执行此操作App.Device.SetLocation(latitude, longitude)
...其中 latitude
和 longitude
是包含所需坐标的双精度类型的变量。
这在 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 位数字,但它没有帮助。除此之外,我尝试对坐标进行硬编码并使用 float
s 而不是 double
s 但两种尝试均无效。
这是怎么回事,如何解决?
这是我的设置:
- Xamarin.UITest 版本 2.2.4
- iOS 模拟器 运行 iOS 9.3 on an iPhone 6
- 主机:Macmini 运行MacOS High Sierra 10.13.6
同样的问题在几个月前使用以下设置发生:
- Xamarin.UITest 版本 2.2.1
- iOS 模拟器 运行 iOS 11.2 在 iPhone X 上
- 主机:Mac Mini 运行 MacOS High Sierra (10.13.3)
当时我就不管了,现在是我该修的时候了。
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;