2016-06-10 23 views
2

我有一個啓動屏幕,顯示3秒鐘,然後淡入新視圖。在這個觀點上,有一個叫做「隱私政策」的UILabel,我附上了UIGestureRecognizer。我正在嘗試使用UI測試來點擊該標籤來觸發導航控制器。這在現實生活中可行,但是,在UI測試期間,水龍頭不會做任何事情。我的代碼如下所示:UI測試tap()不起作用

func testPrivacyPolicyLink() { 
    let app = XCUIApplication() 

    let exists = NSPredicate(format: "exists == 1") 
    expectationForPredicate(exists, evaluatedWithObject: app.images["Logo"], handler: nil) 

    waitForExpectationsWithTimeout(5) { error in 
     XCTAssertNil(error, "Splash screen took too long") 
     sleep(4) // Added this just to make sure the splash screen has fully faded away 
     app.staticTexts["Privacy Policy"].tap() // Should trigger a navigation controller push, but doesn't do anything 
    } 
} 

記錄UI測試對於這種情況即使,它調用app.staticTexts["Privacy Policy"].tap()其中工程。但是當我回放時,它不起作用。任何幫助,將不勝感激!

+0

爲什麼不使它成爲一個按鈕? –

+1

@LukePatterson這很複雜......但這應該不重要? – Tometoyou

+0

如果它在現實生活中有效,爲什麼你需要測試它? – user2277872

回答

1

您需要設置此視圖的輔助功能特徵爲「按鈕」或「鏈接」,以便可訪問性系統清楚該元素是否可觸摸。您可以在工具窗格中的Interface Builder中,選擇Identity檢查設置,並設置無障礙標識和traits類 Identity inspector screenshot

或者你也可以在代碼中做到這一點

self.view.accessibilityTraits = UIAccessibilityTraitButton; 
self.view.accessibilityIdentifier = "departments selection";