NSPredicate API

该API并不是iOS9.0才有的,但是在UI Testing中用到了,所以有必要要学习下

属性

方法

实例


func testXCUIElementQueryByElement() {
        // Use recording to get started writing UI tests.
        // Use XCTAssert and related functions to verify your tests produce the correct results.

        let app = XCUIApplication()
        //获取所有textField的query对象
        let query = app.windows.textFields
        let element = query.element
        //创建匹配器,匹配placeholderValue的值为Type in number的控件
        let predicate = NSPredicate(format: "placeholderValue == %@", "Type in number")

        let button = query.elementMatchingPredicate(predicate);
        let button2 = query.elementAtIndex(0)



        if(button.exists){
            button.tap()
            button.typeText("button")
        }
        if(button2.exists){
            button2.tap()
            button2.typeText("button2")
        }
        //创建匹配器,匹配placeholderValue的值为Type in number且value值为Hello的控件
        let predicate1 = NSPredicate(format: "value == %@ AND placeholderValue == %@", "button","Type in number")
        let button3 = query.elementMatchingPredicate(predicate1);
        if(button3.exists){
            button3.tap()
            button3.typeText("button3")
        }

        //根据elementMatchingType方法查找元素
        let button4 = query.elementMatchingType(.TextField, identifier: "")
        if(button4.exists){
            button4.tap()
            button4.typeText("button4")
        }
    }

你可能感兴趣的:(NSPredicate API)