Programing

Xcode UI 테스트-UI 테스트 실패-검색 필드 "취소"버튼을 탭할 때 표시 (AX 작업에 의해)로 스크롤하지 못했습니다.

lottogame 2020. 11. 8. 09:09
반응형

Xcode UI 테스트-UI 테스트 실패-검색 필드 "취소"버튼을 탭할 때 표시 (AX 작업에 의해)로 스크롤하지 못했습니다.


검색 창에서 '취소'버튼을 눌러 검색 창을 닫으려고합니다.

테스트 케이스가 취소 버튼을 찾지 못했습니다. Xcode 7.0.1에서 잘 작동했습니다.

버튼이 나타날 때까지 기다리는 술어를 추가했습니다. "취소"버튼을 누르면 테스트 케이스가 실패합니다.

let button = app.buttons[“Cancel”]
let existsPredicate = NSPredicate(format: "exists == 1")

expectationForPredicate(existsPredicate, evaluatedWithObject: button, handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)

button.tap() // Failing here

로그 :

    t =     7.21s     Tap SearchField
t =     7.21s         Wait for app to idle
t =     7.29s         Find the SearchField
t =     7.29s             Snapshot accessibility hierarchy for com.test.mail
t =     7.49s             Find: Descendants matching type SearchField
t =     7.49s             Find: Element at index 0
t =     7.49s             Wait for app to idle
t =     7.55s         Synthesize event
t =     7.84s         Wait for app to idle
t =     8.97s     Type 'vinayak@xmd.net' into
t =     8.97s         Wait for app to idle
t =     9.03s         Find the "Search" SearchField
t =     9.03s             Snapshot accessibility hierarchy for com.test.mail
t =     9.35s             Find: Descendants matching type SearchField
t =     9.35s             Find: Element at index 0
t =     9.36s             Wait for app to idle
t =     9.42s         Synthesize event
t =    10.37s         Wait for app to idle
t =    10.44s     Check predicate `exists == 1` against object `"Cancel" Button`
t =    10.44s         Snapshot accessibility hierarchy for com.test.mail
t =    10.58s         Find: Descendants matching type Button
t =    10.58s         Find: Elements matching predicate '"Cancel" IN identifiers'
t =    10.58s     Tap "Cancel" Button
t =    10.58s         Wait for app to idle
t =    10.64s         Find the "Cancel" Button
t =    10.64s             Snapshot accessibility hierarchy for com.test.mail
t =    10.78s             Find: Descendants matching type Button
t =    10.78s             Find: Elements matching predicate '"Cancel" IN identifiers'
t =    10.79s             Wait for app to idle
t =    11.08s         Synthesize event
t =    11.13s             Scroll element to visible
t =    11.14s             Assertion Failure: UI Testing Failure - Failed to scroll to visible (by AX action) Button 0x7f7fcaebde40: traits: 8589934593, {{353.0, 26.0}, {53.0, 30.0}}, label: 'Cancel', error: Error -25204 performing AXAction 2003

나는 여기에 "취소"버튼 falsehittable속성에 대해 반환 되는 것 같아요 .

당신이 볼 경우 tap()설명서에 말한다

/*!
 * Sends a tap event to a hittable point computed for the element.
 */
- (void)tap;

XCode 7.1로 인해 문제가 발생한 것 같습니다. 이러한 문제로부터 자신을 차단하지 않기 위해 (그리고 u도;)) 히트 XCUIElement가능하지 않더라도 요소를 탭할 수 있는 확장 프로그램을 작성했습니다 . 다음이 도움이 될 수 있습니다.

/*Sends a tap event to a hittable/unhittable element.*/
extension XCUIElement {
    func forceTapElement() {
        if self.hittable {
            self.tap()
        }
        else {
            let coordinate: XCUICoordinate = self.coordinateWithNormalizedOffset(CGVectorMake(0.0, 0.0))
            coordinate.tap()
        }
    }
}

이제 다음과 같이 호출 할 수 있습니다.

button.forceTapElement()

업데이트 -신속한 3의 경우 다음을 사용하십시오.

extension XCUIElement {
    func forceTapElement() {
        if self.isHittable {
            self.tap()
        }
        else {
            let coordinate: XCUICoordinate = self.coordinate(withNormalizedOffset: CGVector(dx:0.0, dy:0.0))
            coordinate.tap()
        }
    }
}

저에게 근본 원인은 제가 탭하고 싶은 오브젝트가

  • 숨김 (및 뒤로)으로 설정되었습니다.
  • 제거되었다가 다시 연결되었습니다

두 경우 모두 isAccessibilityElement재산은 false그 후 였습니다 . 다시 설정하여 true수정했습니다.


이 질문은 "표시된 (AX 작업에 의해) 버튼으로 스크롤하지 못함" 이라는 용어에 대한 Google 검색어의 순위 가 높습니다 . 질문의 나이를 감안할 때 나는 이것이 더 이상 XCUITest 프레임 워크의 문제가 아니라고 생각했습니다.

이 문제는 XCElement기존에 있지만 소프트웨어 키보드 뒤에 숨겨져 있기 때문이라는 것을 알았습니다 . 탭할 수 있도록 뷰에 존재하는 뷰를 스크롤 할 수 없기 때문에 프레임 워크에서 오류가 발생합니다. 제 경우에는 문제의 버튼이 때때로 소프트웨어 키보드 뒤에있었습니다 .

iOS 시뮬레이터의 소프트웨어 키보드가 어떤 경우 (예 : 컴퓨터에서) 꺼지고 다른 경우 (예 : CI에서) 켜질 수 있음을 발견했습니다. 제 경우에는 한 컴퓨터에서 소프트웨어 키보드를 끄고 기본적으로 다른 컴퓨터에서는 켜졌습니다.

해결 방법 : 키보드 뒤에있을 수있는 버튼을 누르기 전에 키보드를 닫으십시오.

버튼을 누르기 전에 키보드를 명시 적으로 닫는 곳을 두드리면 모든 환경에서 내 문제가 해결되었습니다.

현재 응답자가 resignFirstResponder에 도달하도록 몇 가지 작업을 추가했습니다. 내 텍스트보기 뒤에있는보기로 인해 첫 번째 응답자가 사임해야하므로 마지막 텍스트 영역 바로 아래를 탭합니다.

 /// The keyboard may be up, dismiss it by tapping just below the password field
let pointBelowPassword = passwordSecureTextField.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 1))
pointBelowPassword.press(forDuration: 0.1)

요소의 특성을 확인하십시오. TableViewSectionHeader와 동일한 문제에 직면했습니다. 탭을 시도했지만 모든 지점에서 실패했습니다.

enter image description here


제 경우에는 버튼을 덮는 프로그래밍 방식으로 추가 된 UI 요소가있었습니다.


AppCenter 시뮬레이터를 사용하여 테스트를 실행하는 경우 로컬 시뮬레이터와 동일한 디바이스 버전에서 테스트를 실행하고 있는지 확인해야합니다. 이 때문에 3 일의 일을 잃었습니다.


Sandy의 해결 방법은 잠시 동안 도움이 된 것처럼 보였지만 더 이상은 아닙니다. 그런 다음 다음과 같이 변경했습니다.

func waitAndForceTap(timeout: UInt32 = 5000) {
    XCTAssert(waitForElement(timeout: timeout))
    coordinate(withNormalizedOffset: CGVector(dx:0.5, dy:0.5)).tap()
}

Main point being that as the issue is that isHittable check throws an exception, I don't do this check at all and go straight for coordinates after the element is found.

참고URL : https://stackoverflow.com/questions/33422681/xcode-ui-test-ui-testing-failure-failed-to-scroll-to-visible-by-ax-action

반응형