問題描述
我正在考慮使用 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:以協調的方式跨兩個應用程序運行測試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!