2015-10-29 88 views
1

我試着新的Xcode的UI測試,並收到以下錯誤的Xcode 7的UI測試訪問欄按鈕項目

func testLogout() { 

    let app = XCUIApplication() 
    let tablesQuery = app.tables 
    let passwordSecureTextField = tablesQuery/*@[email protected]*/.secureTextFields["Password"]/*[[".cells.secureTextFields[\"Password\"]",".secureTextFields[\"Password\"]"],[[[-1,1],[-1,0]]],[0]]@[email protected]*/ 
    passwordSecureTextField.tap() 
    passwordSecureTextField/*@[email protected]*/.pressForDuration(1.2);/*[[".tap()",".pressForDuration(1.2);"],[[[-1,1],[-1,0]]],[0]]@[email protected]*/ 
    app/*@[email protected]*/.menuItems["Paste"]/*[[".menus.menuItems[\"Paste\"]",".menuItems[\"Paste\"]"],[[[-1,1],[-1,0]]],[0]]@[email protected]*/.tap() 

    let poReceiverNavigationBar = app.navigationBars["PO Receiver"] 
    poReceiverNavigationBar.buttons["Login"].tap() 

    let menuIcoButton = poReceiverNavigationBar.buttons["menu ico"] 
    menuIcoButton.tap() 

誤差

no maches found for "menu ico" Button 
其實

它沒有連接它的自定義欄按鈕項目,通過IBOutlet。問題是我可以通過座標或水手以其他方式訪問該按鈕嗎?或者一些其他的解決辦法

+0

你獲得通過錄制該按鈕的標識?會發生什麼,爲什麼你嘗試'staticTexts []'? – cakes88

+0

哦,你能告訴我如何通過錄音得到該按鈕的標識符嗎?請__) –

+0

[查看此博客文章從mokacoding](http://www.mokacoding.com/blog/xcode-7-ui-testing/),第二張圖片向下展示給你。也有很多關於入門的信息 – cakes88

回答

2

是的,你可以通過特定的座標中進行選擇:

extension XCUIElement { 
     func tapAtPosition(let position: CGPoint) { 
      let cooridnate = self.coordinateWithNormalizedOffset(CGVector(dx: 0, dy: 0)).coordinateWithOffset(CGVector(dx: position.x, dy: position.y)) 
      cooridnate.tap() 
     } 
    } 
+0

嘿,self.coordinateWithNormalizedOffset是什麼類型? –

+0

編輯答案,需要擴展XCUIElement – cakes88

+1

yeap,我只是做了同樣的:) –