Xcode 7 UI 测试访问栏按钮项目

Xcode 7 UI tests Access Bar Button Item

我正在尝试新的 xcode ui 测试并得到以下错误

func testLogout() {

    let app = XCUIApplication()
    let tablesQuery = app.tables
    let passwordSecureTextField = tablesQuery/*@START_MENU_TOKEN@*/.secureTextFields["Password"]/*[[".cells.secureTextFields[\"Password\"]",".secureTextFields[\"Password\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/
    passwordSecureTextField.tap()
    passwordSecureTextField/*@START_MENU_TOKEN@*/.pressForDuration(1.2);/*[[".tap()",".pressForDuration(1.2);"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/
    app/*@START_MENU_TOKEN@*/.menuItems["Paste"]/*[[".menus.menuItems[\"Paste\"]",".menuItems[\"Paste\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.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 连接。问题是我可以通过坐标或 smth 以其他方式访问该按钮吗?或者其他一些解决方案

是的,您可以 select 通过特定坐标:

    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()
        }
    }