0

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

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

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

4

2 回答 2

0

斯威夫特 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
            })
        }
于 2019-02-27T05:16:18.043 回答
0

如果您想为您的 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()
    }
}
于 2019-02-27T11:53:07.710 回答