XCUITest:以协调的方式跨两个应用程序运行测试

时间:2023-03-24
本文介绍了XCUITest:以协调的方式跨两个应用程序运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在考虑使用 XCUITest 对我的 iOS 应用程序进行 UI 测试.看起来 XCUITest 具有广泛的功能,包括使用多个应用程序的能力.但是,多应用支持似乎有些受限.

I am looking at using XCUITest for UI tests for my iOS apps. It looks like XCUITest has a wide arrange of functionality, including the ability to work with multiple apps. However, the multiple app support seems somewhat limited.

似乎使用 XCUIApplication 我可以使用 Bundle ID 启动另一个应用程序,甚至可以监控它的状态.但是,我想做的是能够为两个具有紧密交互的应用程序运行协调测试(例如,一个应用程序对另一个应用程序执行打开 URL,执行一些 UI 操作,然后返回到第一个应用程序).

It seems that using XCUIApplication I can start another app using Bundle ID and even monitor its state. However, what I want to do is be able to run a coordinated test for two apps that have tight interaction (for example, one app does an open URL to another app, performs some UI action, and then returns to the first app).

这可能只使用 XCUITest,还是我需要一些更高级别的工具?(我认为有一些工具可以做到这一点,但如果可能的话,我更愿意继续使用 XCUITest)

Is this possible just using XCUITest, or do I need some higher level tool? (I think some tools exist that can do this but would prefer to stay with XCUITest if possible)

理想情况下,我会将所有代码放在一个文件中,以便在两个应用程序中执行 UI 操作.但如果这是不可能的,我愿意编写单独的测试应用程序,这些应用程序有效地相互移交,在轮到"时执行操作.但我不确定如何协调这两个测试应用程序.

Ideally, I would have all the code in a single file that executed the UI actions in the two apps. But if that was impossible, I would be open to writing to separate test apps which effectively hand off to one other, performing actions when it is their 'turn'. But I am not sure how I would work the coordination of the two tests apps.

推荐答案

这实际上在 Xcode 9 中得到了很好的支持.下面是如何设置它:

This is actually supported really nicely in Xcode 9. Here's how to set it up:

我发现最简单的方法是创建一个包含您的两个应用程序的工作区.在包含您的 UI 测试代码的应用程序项目中,以执行这两个应用程序,确保这两个应用程序都列在您的 UI 测试目标的目标依赖项下:

I've found the easiest is to create a workspace containing both of your apps. In the app project containing your UI test code to excercise both apps, make sure both apps are listed under Target Dependencies in your UI Test target:

现在只需在测试的设置函数中启动这两个应用程序,使用它们的包标识符:

Now it's just a matter of starting both apps in your setup function of your test, using their bundle identifiers:

app1 = XCUIApplication(bundleIdentifier: "no.terje.app1.App1")
app1.launch()
app2 = XCUIApplication(bundleIdentifier: "no.terje.app2.App2")
app2.launch()

(应用程序是我的测试类的实例成员,var app1: XCUIApplication!)

(the apps are instance members of my test class, var app1: XCUIApplication!)

现在一切就绪.像这样对两个应用程序运行测试:

Now you're all set up. Run tests against both apps like this:

func testButtonsExist() {
  app1.activate()
  app1.buttons["mybutton"].exists
  app2.activate()
  app2.buttons["myotherbutton"].exists
}

至于您提到的等待或异步挑战:我想其中大多数也存在于单个应用程序中的异步代码中,例如等待打开 URL.但是,如果您遇到特定问题,请发布您正在尝试和失败的特定事情.

As for the waiting or async challenges you are mentioning: I would imagine most of those exist for async code within a single app too, for example waiting for a URL to open. But do post a specific thing you are trying and failing if you have specific problems.

这篇关于XCUITest:以协调的方式跨两个应用程序运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:安卓服务测试 下一篇:android 仪器测试的输出在哪里?

相关文章