Xamarin.UITests-在真实设备上进行测试-iOS-应用权限弹出窗口问题 [英] Xamarin.UITests - testing on real device - iOS - app permissions popups issue

查看:81
本文介绍了Xamarin.UITests-在真实设备上进行测试-iOS-应用权限弹出窗口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS应用需要一些特权(GPS,推送通知).当应用程序首次启动时,iOS会询问用户是否可以将这些权限授予应用程序.我已经编写了一些UITest,并希望在本地连接的iPhone上自动运行它们.

问题是我无法覆盖权限问题,并且测试失败.我发现,由IDE(Xamarin Studio)部署的应用程序将询问权限,但通过UITests部署的应用程序则不会.因此,我尝试使用 .AppBundle(path_to_app),但是它说这仅适用于部署到Simulator.

SetUp:System.Exception:此应用捆绑包对于在以下位置运行无效模拟器.要解决此问题,请确保您的目标设备是一个模拟器.DTPlatformName是'iphoneos',而不是'iphonesimulator'应用程序的Info.plist.

就像它试图将iPhone应用程序部署到Simulator一样.但是Xamarin Studio中的Target设置为真实设备.我试图添加 .DeviceIdentifier .与 .InstalledApp 一起使用时,它正在启动(仍在询问权限).但是当我使用 DeviceIdentifier AppBundle 时,出现了与上述相同的错误.

我的测试在Test Cloud上运行良好.他们在模拟器上工作正常.当我手动部署到设备,启动应用程序并批准权限然后运行UI测试时,它们可以正常工作.

我无法实现的是使UITests覆盖真实设备上的权限问题.有人做过这项工作吗?

最后是我发现是在 AppBundle 方法的文档中将强制在模拟器上运行" https://developer.xamarin.com/api/member/Xamarin.UITest.Configuration.iOSAppConfigurator.AppBundle/p/System.String/

所以我可能注定要完成任务,但也许有人知道解决方法?

解决方案

您可以使用InvokeUIA使用UITest关闭系统对话框.点击iOS系统警报的确定"按钮,可以进行以下测试:

  [测试]公共无效AppLaunches(){app.Screenshot(第一屏".);app.InvokeUia("uia.query('[:view {:marked \" OK \}]')"));app.InvokeUia("uia.tapMark(\" OK \)");} 

一个工作示例应用程序&UITest也位于此处: https://github.com/King-of-Spades/InvokeUia-for-System-Dialogs

关于测试云中系统对话框的警告

您在测试云"中看不到此问题的原因是,测试云"会自动关闭系统警报;因此通常您不必担心.但是,如果您的警报启动得太早;使其出现在自动化程序完全启动您的应用程序之前,那么它将无法检测到&解除警报,并导致测试失败.

因此,您要确保在Test Cloud中运行应用程序时,对权限的请求被延迟,或者,如果特定测试没有明确要求,则甚至可以取消激活它们.可在此Calabash指南中获得更多信息: https://developer.xamarin.com/guides/testcloud/UITest/xcode7/

  • 瓢虫: https://developer.xamarin.com/guides/testcloud/calabash/xcode7/#Automation_API
  • I've iOS app that needs some privileges (GPS, Push notifications). When app starts for a first time iOS asks user if they're ok with granting those permissions to application. I've written some UITests and want to automate running them on locally connected iPhone.

    The problem is that I cannot override permissions questions and my tests fails. I found out that application deployed by IDE (Xamarin Studio) will ask for permissions, but application deployed via UITests will not. So I tried with .AppBundle(path_to_app) but it says this is only valid for deploying to Simulator.

    SetUp : System.Exception : This app bundle is not valid for running on a simulator. To fix this issue please ensure that your target device is a simulator. DTPlatformName is 'iphoneos', not 'iphonesimulator' in the apps Info.plist.

    Like it's trying to deploy iPhone app to Simulator. But Target in Xamarin Studio is set to real device. I tried to add .DeviceIdentifier. When Used with .InstalledApp it was starting up (still asking for permissions). But when I used DeviceIdentifier and AppBundle there was the same error as above.

    My tests works fine on Test Cloud. They work fine on Simulator. They work fine when I deploy to device manually, start app and approve permissions then run UI tests.

    What I cannot achieve is to make UITests override permissions questions on real device. Anyone made this work?

    Last thing is that I found is in documentation for AppBundle method "Will force a run on simulator" https://developer.xamarin.com/api/member/Xamarin.UITest.Configuration.iOSAppConfigurator.AppBundle/p/System.String/

    So I may be doomed with the task but maybe someone knows a workaround?

    解决方案

    You can dismiss system dialogs with UITest by using InvokeUIA. The test below works by tapping the "OK" button of an iOS system alert:

    [Test]
    public void AppLaunches ()
    {
        app.Screenshot ("First screen.");
        app.InvokeUia ("uia.query('[:view {:marked \"OK\"}]')"); 
        app.InvokeUia ("uia.tapMark(\"OK\")"); 
    }
    

    A working sample app & UITest is also here: https://github.com/King-of-Spades/InvokeUia-for-System-Dialogs

    Warning about system dialogs in Test Cloud

    The reason that you don't see this issue in Test Cloud is because Test Cloud automatically dismisses the system alerts; so usually you don't have to worry about it. However, if your alert launches too soon; so that it appears before the automation has fully started your app, then it will be unable to detect & dismiss the alert and cause your test to fail.

    So you want to make sure that when running your app in Test Cloud that the request for permissions are delayed, or you can even deactivate them if they aren't explicitly needed for a particular test. More information is available in this Calabash guide: https://github.com/calabash/calabash-ios/wiki/Managing-Privacy-Alerts%3A--Location-Services%2C-APNS%2C-Contacts

    (Even though it's Calabash, you can use the same strategy in UITest; albeit with a C# syntax.)

    Update for Xcode 8 / iOS 10

    Xcode 8 / iOS 10 removed UIAutomation, so the InvokeUIA workaround will only continue to be possible if you're using Xcode 7 and iOS 7-9. References:

    这篇关于Xamarin.UITests-在真实设备上进行测试-iOS-应用权限弹出窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆