【问题标题】:How to kick user back on homepage without using Navigations in IOS app如何在不使用 IOS 应用中的导航的情况下将用户踢回主页
【发布时间】:2019-02-26 23:51:56
【问题描述】:

背景- 我有一个 Ios Native 应用程序,我正在 XCUITest 中自动化测试脚本。类中当前的测试用例流程是作为设置设备,安装应用打开应用->登录->执行操作

对于第二个测试用例方法,它首先使用导航从第一个测试用例操作中注销并启动

有没有什么方法可以在每个测试用例方法运行结束后直接跳转到主页而不使用导航?导航需要额外的时间来运行大型套件。

【问题讨论】:

    标签: ios xcuitest testautomationfx


    【解决方案1】:

    斯威夫特 4.2

    我想不明白你的问题,但如果你想在没有导航的情况下跳转到主页,你可以使用这行代码:

    UIApplication.shared.keyWindow?.rootViewController = HomeViewController()
    

    如果你不想用小动画跳起来,使用这个:

    DispatchQueue.main.async {
                guard let window = UIApplication.shared.keyWindow else { return }
                UIView.transition(with: window, duration: 0.5, options: .allowUserInteraction, animations: {
                    UIApplication.shared.keyWindow?.rootViewController = HomeViewController()
                }, completion: { completed in
                })
            }
    

    【讨论】:

      【解决方案2】:

      如果您想为您的 UI 测试实现更快的导航,您可以利用使用启动参数启动应用程序的好处。

      编辑方案 > 运行 > 将“UITEST”添加到启动时传递的参数

      例如在你的代码中定义

      class AppDelegate: UIResponder, UIApplicationDelegate {
      
          var uiTestModeKey = "UITEST"
          static var uiTestMode = false
          func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
              // Override point for customization after application launch.
              if (CommandLine.arguments.contains(uiTestModeKey)) {
                 AppDelegate.uiTestMode = true
              }
              return true
          }
      }
      

      在您想要快速返回的部分中,您可以定义如下内容:

      func onActionComplete() {
          if (AppDelegate.uiTestMode) {
              navigationController?.popToRootViewController(animated: false)
              //Or set the window to a new instance like
              //UIApplication.shared.keyWindow?.rootViewController = HomeViewController()
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-20
        • 1970-01-01
        • 2021-11-13
        • 2020-11-28
        • 2020-09-30
        • 1970-01-01
        • 1970-01-01
        • 2019-01-07
        相关资源
        最近更新 更多