Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UI testing - No matches found for Descendants matching type... recording generated code

I am getting an error

No matches found for Find: Descendants matching type NavigationBar from input {( Application, 0x60400019b790, pid: 20515, label: '<appname>' )}

but the code was generated by the recording function of XCUITest so I don't understand why it can't find the navbar. I have added an accessibilityIdentifier that is a localized string called dashboardNavBar to try and use that to find it instead but I am having trouble querying it. The current code I am using is:

func testLoginLogout() {
    let app = XCUIApplication()
    //login credentials and other code that takes me to dashboard of app
    app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
    app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
}

and the app.navigationBars... line is the line that throws the error above. I was hoping someone could tell me why it is unable to locate this navBar or whatever the problem is, and how I can fix it or work around it using the accessibilityIdentifier. Thanks.

like image 728
donutjuice101 Avatar asked Nov 30 '17 18:11

donutjuice101


1 Answers

I know that it's might be a workaround and not a real solution, but what I did when I encountered this problem is added a check if the element exist and trying to run the same action two times. When you make a segue after this action, the element should not exist, and the second attempt to invoke won't be executed. For instance:

    func testLoginLogout() {
            let app = XCUIApplication()
            if (app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).exists) {
                app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
            }
// and if you will call it again the element should not exists, otherwise it will be called again

            if (app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).exists) {
                app.navigationBars["Dashboard"].children(matching: .button).element(boundBy: 2).tap()
            }

            if (app.sheets["Do you want to Logout ?"].buttons["OK"].exists) {
                app.sheets["Do you want to Logout ?"].buttons["OK"].tap()
            }
        }
like image 122
Max Niagolov Avatar answered Sep 17 '22 21:09

Max Niagolov