2017-11-20 1 views
1

UITest를 성공적으로 전달할 수있는 작업이 있습니다. 예상되는 요소 (제 경우의 경고)가 시간 초과 (서버 요청시) 전에 나타나지 않은 경우.waitForExpectations 실패시 UITest에서 성공하기

코드 :

let element = app.alerts["test text"] 
let existsPredicate = NSPredicate(format: "exists == true") 
expectation(for: existsPredicate, evaluatedWith: element, handler: nil) 

waitForExpectations(timeout: 10, handler: nil) 

// when timeout expired test should finish with success 

는 인터넷을 통해 해결책을 찾지 못했습니다.

답변

1

О®®, 기꺼이 UITest입니다. 그 경우에 기대는 좋은 재산을 가지고있다 : isInverted. 이것을 true로 설정하면 기대가 일어나지 않을 것이라고합니다.)))

let element = app.alerts["test text"] 
let existsPredicate = NSPredicate(format: "exists == true") 
let expectation = expectation(for: existsPredicate, evaluatedWith: element, handler: nil) 
expectation.isInverted = true // if alert doesn't appear during 10 seconds, then test passed 

waitForExpectations(timeout: 10, handler: nil) 
+0

재미 있습니다! 코드 예제를 게시하십시오. – Igor

+0

Brilliant! 그것은 내가 필요한 것! 이 단서를 가져 주셔서 감사합니다! 우편 번호와 나는 당신의 대답을 받아 들일 것입니다. – Igor

+0

직접 추가했습니다. 이전 대답을 삭제하십시오. – Igor

관련 문제