5

I have a view controller that is presented using a "Present As Popover" segue. When I run the app it works as expected and tapping outside of the popover will dismiss it. However, when I run my UI test, I can't get the popover to dismiss. How should I do this? I've tried:

app.otherElements["PopoverDismissRegion"].tap()

But the logs print:

Unable to find hit point for Other 0x61000017f8c0: traits: 35184372088832, {{0.0, 0.0}, {375.0, 667.0}}, identifier: 'PopoverDismissRegion', label: 'dismiss popup'

beyerss
  • 1,302
  • 3
  • 21
  • 38

2 Answers2

5

There's a bug in Xcode UI Tests recording.

Popover dismissal is recorded as:

app.otherElements["PopoverDismissRegion"].tap()

In reality the following is needed (as revealed by Accessibility Inspector):

app.otherElements["dismiss popup"].tap()

Handy extension:

extension XCUIApplication {
    func dismissPopup() {
        otherElements["dismiss popup"].tap()
    }
}
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
  • 1
    Please review [How do I write a good answer](https://stackoverflow.com/help/how-to-answer). Code-only answers are discouraged because they do not explain how they resolve the issue in the question. You should update your answer to explain what this does and how to use it. – FluffyKitten Oct 12 '17 at 21:26
  • @FluffyKitten Better? – Rudolf Adamkovič Oct 12 '17 at 22:23
  • Thanks for updating your answer to explain the code. Your answer had been flagged as low quality, as it was code-only. Its not up to me alone, but it looks good to me and should pass the review process :) – FluffyKitten Oct 13 '17 at 08:02
2

Add this line where you want to dismiss the popover

app.children(matching: .window).element(boundBy: 0).tap()
rameez
  • 374
  • 2
  • 11
  • 1
    That still does not work for me. It looks like this tries to tap in the center of the screen. The view controller in my popover covers the center of the screen and the result is just that a different row in the table view that is contained in my view controller gets selected. – beyerss May 11 '17 at 14:39
  • Do you have some other elements on screen you can try tapping on those. – rameez May 11 '17 at 15:06