2016-02-09 25 views
1

我想測試一個UiImagePicker我已經在Xcode上使用記錄功能來獲取我的大部分測試,但它未能捕獲一個元素來確認我想要選擇的圖片。同樣的事情發生在另一個選項「哪個是取消」我記得某種方式來獲得視圖上的所有元素的列表或某種效果。所以我的問題如何獲得對視圖中ImagePicker對象的選項的引用。測試UIImagePicker

我建立了iOS9和運行Xcode7.2

我目前的測試看起來像這樣 ` FUNC testMenu(){ loginInApp(APP)//獲取您過去的登錄

app.buttons["LogoButton"].tap() //entry point for menuView 

    XCTAssert(app.buttons["BR"].exists) 
    let brButton = app.buttons["BR"] 
    brButton.tap() 

    let photosFromSheet = app.sheets["Where would you like to get photos from?"] 
    XCTAssert(photosFromSheet.exists) 
    photosFromSheet.staticTexts["Where would you like to get photos from?"].tap() 
    XCTAssert(photosFromSheet.collectionViews.buttons["Chose from Library"].exists && photosFromSheet.buttons["Cancel"].exists) 
    photosFromSheet.collectionViews.buttons["Chose from Library"].tap() 
    XCTAssert(app.tables/*@[email protected]*/.buttons["Moments"]/*[[".cells[\"Moments\"].buttons[\"Moments\"]",".buttons[\"Moments\"]"],[[[-1,1],[-1,0]]],[0]]@[email protected]*/.exists) 
    app.tables/*@[email protected]*/.buttons["Moments"]/*[[".cells[\"Moments\"].buttons[\"Moments\"]",".buttons[\"Moments\"]"],[[[-1,1],[-1,0]]],[0]]@[email protected]*/.tap() 
    XCTAssert(app.collectionViews.cells["Photo, Landscape, March 12, 2011, 4:17 PM"].exists) 
    app.collectionViews.cells["Photo, Landscape, March 12, 2011, 4:17 PM"].tap() 

XCTAssert(app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(。其他).elementBoundByIndex(2).childrenMatchingType(。其他).element.exists)

//這裏是事情變得模棱兩可的地方,當測試運行時,實際上並沒有選擇任何東西。

app.childrenMatchingType(.Window).elementBoundByIndex(0).childrenMatchingType(。其他).elementBoundByIndex(2).childrenMatchingType(。其他).element.tap()


brButton.tap() 
    photosFromSheet.buttons["Cancel"].tap() 
    app.buttons["LogoButton"].tap() 

`

+0

在這個模糊的行之前放置一個斷點,然後在控制檯中運行'po app.debugDescription',它將打印UI的輔助功能層次結構。應該幫助弄清楚測試主機正在看到什麼。 – ishaq

+0

也沒有在那裏顯示。 –

+0

這解決了我的問題,但不適用於6S + http://stackoverflow.com/questions/33422681/xcode-ui-test-ui-testing-failure-failed-to-scroll-to-visible-by-ax-action/33534187#33534187 –

回答

0

的UIImagePicker顯然不是hittable 所以這種解決方法

如果您在文檔中看到水龍頭(),它說

/*! 
* Sends a tap event to a hittable point computed for the element. 
*/ 
- (void)tap; 


/*Sends a tap event to a hittable/unhittable element.*/ 
extension XCUIElement { 
    func forceTapElement() { 
     if self.hittable { 
      self.tap() 
     } 
     else { 
      let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0)) 
      coordinate.tap() 
     } 
    } 
} 

現在你可以調用作爲

button.forceTapElement() 

這不會對6S +壽工作。希望這將很快得到解決。