代码之家  ›  专栏  ›  技术社区  ›  vatbub

Xamarin Uitest“无法在iOS模拟器上设置假位置”

  •  1
  • vatbub  · 技术社区  · 7 年前

    我正在使用xamarin.uitest在Android和iOS上测试一个xamarin表单应用程序。由于应用程序取决于GPS位置,所以我需要设置一个假位置。我这样做是用

    App.Device.SetLocation(latitude, longitude)
    

    …在哪里 latitude longitude 是包含所需坐标的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位可能会有帮助,但没有帮助。除此之外,我试图硬编码坐标并使用 float 而不是 double 但两次尝试都没有成功。

    那里发生了什么事,怎么修理?

    以下是我的设置:

    • Xamarin.uitest版本2.2.4
    • 在iPhone6上运行iOS 9.3的iOS模拟器
    • 主机:Mac Mini运行MacOS High Sierra 10.13.6

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

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

    当时,我只是把它放在一边,但现在正是我需要解决的时候。

    1 回复  |  直到 7 年前
        1
  •  1
  •   SushiHangover    7 年前

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

    en-US

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