在我的項目中使用Xcode啓動UI測試,碰到路障。Xcode UI測試如何在自定義類文本字段中輸入文本
有一個叫RSCustomTextField
的UITextField
子類,有一些UI自定義。它被添加到RSSearchHeadView
,其中包含文本字段和按鈕。
所以我不是能夠查詢文本框爲app.textfields["Search field"]
因爲它的自定義類,它顯示爲app.otherElements["Search field"]
它崩潰的searchField.typeText("abc")
顯示錯誤無論元素也沒有任何後代具有鍵盤焦點。。
即使在tap()
的元素。請注意,我也嘗試在子類和文本框上設置輔助功能特性爲UIAccessibilityTraitSearchField
,但沒有區別。
func testSearchIcon() {
let searchField = app.otherElements["Search field"]
searchField.tap()
searchField.typeText("abc")
app.keys["delete"].tap()
XCTAssertFalse(searchDubizzleElement.hittable)
}
印刷debugDescription
上的應用程序提供了以下的輸出:
Element subtree:
→Application 0x7fc1b3f3aa00: {{0.0, 0.0}, {375.0, 667.0}}, label: 'myappname-masked'
Window 0x7fc1b3f439b0: Main Window, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f55c20: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f43440: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f31830: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f61ff0: traits: 8589934592, {{0.0, 0.0}, {375.0, 667.0}}
Other 0x7fc1b3f52820: traits: 8589934592, {{0.0, 0.0}, {375.0, 64.0}}
Other 0x7fc1b3f4e190: traits: 8589934592, {{0.0, 0.0}, {375.0, 64.0}}
Button 0x7fc1b3f3a250: traits: 8589934593, {{5.0, 20.0}, {44.0, 44.0}}, label: 'search icon right'
Other 0x7fc1b3f349b0: traits: 8589935616, {{15.0, 20.0}, {345.0, 39.0}}, label: 'Search field'
Image 0x7fc1b3f3b3b0: traits: 8589934596, {{139.0, 22.0}, {97.0, 30.0}}, identifier: 'logo'
Button 0x7fc1b3f537a0: traits: 8589934593, {{326.0, 20.0}, {44.0, 44.0}}, label: 'your account icon'
CollectionView 0x7fc1b3f32450: traits: 35192962023424, {{0.0, 64.0}, {375.0, 603.0}}
Cell 0x7fc1b3f1e230: traits: 8589934592, {{0.0, 64.0}, {375.0, 50.0}}
......
我只是試圖子類的UITextField將其添加到故事板和'debugDescription'顯示元素是一個文本字段。 RSCustomTextField真的只是UITextField的一個子類嗎? –
你嘗試過「app.searchFields.element」嗎? – Che
@TomasCamin你是對的。它沒有直接添加到視圖控制器。它位於另一個名爲'RSSearchHeadView'的自定義視圖內,該視圖只保存'textField'自定義類的按鈕。我已經更新了這個問題。我的錯。任何幫助? – carbonr