2016-06-27 8 views
2

버튼이 활성화되어 있는지 확인한 후 버튼을 탭하려면 어떻게해야합니까?expectationForPredicate를 사용하고 버튼을 누르는 방법

여기에서이 샘플을 찾았지만 내 경우에는 작동하지 않았습니다. 여기

Delay/Wait in a test case of Xcode UI testing

코드의 일부 :

let app = XCUIApplication() 
    let button = app.buttons["Tap me"] 
    let exists = NSPredicate(format: "exists == 1") 
    expectationForPredicate(exists, evaluatedWithObject: button){ 
     button.tap() 
     return true 
    } 
waitForExpectationsWithTimeout(5, handler: nil) 

하지만 내 테스트 버튼으로 눌러 실패합니다. 감사합니다.

+0

코드는 올바른 보이는, 내가/존재하지 않는 버튼을 추측하고하는 버튼이 전무 경우 – Daniel

+0

당신은 확인 했나 찾을 수 없습니다? – LoVo

+0

콘솔 중 : po button.enabled true를 반환합니다. – emoleumassi

답변

3

코드 샘플은 단추가 활성화되어 있는지 확인하지 않습니다 (있을 경우에만).

버튼이있는 경우 expectationForPredicate에 전달 된 블록이 실행되어 버튼이 비활성화 된 경우에도 버튼이 탭됩니다. 버튼에 대한 검사를 포함

이 활성화되고 :

let app = XCUIApplication() 
let button = app.buttons["Tap me"] 
let exists = NSPredicate(format: "exists == 1") 
expectationForPredicate(exists, evaluatedWithObject: button) { 
    // If the button exists, also check that it is enabled 
    if button.enabled { 
     button.tap() 
     return true 
    } else { 
     // Do not fulfill the expectation since the button is not enabled 
     return false 
    } 
} 
waitForExpectationsWithTimeout(5, handler: nil) 
관련 문제