XCUITest:以协调的方式在两个应用程序之间运行测试 [英] XCUITest: Running tests across two apps in a coordinated fashion

查看:220
本文介绍了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:以协调的方式在两个应用程序之间运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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