无法在UI测试中访问我的NSMenu

时间:2018-07-06 10:09:25

标签: xcode-ui-testing xcode9.4

我将NSmenu对象作为statusMenu,我将其辅助功能标识符设置为“ testMenu”

enter image description here

但是当我尝试在下面的UItests中访问它时

        let app = XCUIApplication()
        let menu = app.menus.matching(identifier: "testMenu")
        let count = app.menus.count
        print("menu count is \(count)")
        print("menu count is \(menu.count)")
        if menu.count > 0 {
            XCTAssertTrue(true)
        }
        else {

            XCTAssertTrue(false)
        }

我看到以下错误

`

Replying to query <XCTElementQuery: 0x60c0000a6cc0> with results: (null) (error: Error Domain=com.apple.dt.xctest.automation-support.error Code=2 "No matches found for Find: Elements matching predicate '"testMenu" IN identifiers' from input {(
    Menu, 0x608000183dc0,
    Menu, 0x608000187c50,
    Menu, 0x60800018c300,
    Menu, 0x608000184440,
    Menu, 0x608000188130
)}"`

0 个答案:

没有答案