3

I have a pretty complicated app with a lot of views and popovers for fast picking entries.

I'm not able to dismiss a popover. I tried a lot like:

  • Hitting coordinates in the window
  • app.otherElements["PopoverDismissRegion"] Hitting elements behind the
  • popover (which are not hittable at all)

When I record the it in XCode I get: app.otherElements["PopoverDismissRegion"]

Which makes no sense to me.

Hope someone can help.

Thx

Infos: iOS 10.2,Xcode 8.2.1, iPad Air 2 (Device and Simulator, same results)

Tob
  • 627
  • 6
  • 9
  • your ques is not clear, what you actually want to do ? – vaibhav Jan 27 '17 at 09:46
  • Possible duplicate of [XCode 7 UI Testing: Dismissal of system-generated UIAlertController does not work](http://stackoverflow.com/questions/33124179/xcode-7-ui-testing-dismissal-of-system-generated-uialertcontroller-does-not-wor) – Elist Jan 27 '17 at 09:56
  • 1
    @vaibhav: What is not clear? I have an iPad style popover. I try to dismiss that. – Tob Jan 27 '17 at 14:11
  • @Elist the Popover has no button so no, it's not a duplicate. – Tob Jan 27 '17 at 14:12

3 Answers3

2

EDIT

Found a better solution here:

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

Original solution:

Try this:

XCUIApplication().windows.element(boundBy: 0).tap()

Which taps the window and dismisses the currently active popover.

Zhi An Ng
  • 79
  • 1
  • 4
  • I tried this before, take a look on my second bullet. This was also suggested a lot, but it didn't worked for me. It probably works of an alert controller, but not for a table view which is presented as a popover from a nav bar item. – Tob Apr 14 '17 at 16:06
1

Everything was working for me on iPhone simulators by just doing:

app.swipeDown(velocity: .fast)

I started to have problems when I wanted the same test to run on iPad simulators. The gesture was being applied but it was not big enough to dismiss the view. I tried different things like:

XCUIApplication().windows.element(boundBy: 0).tap()

or

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

but none of the work. The view was still not being dismissed.

Doing more testing on it I found that the view will actually be dismissed sending the swipeDown gesture if iPad Simulator is on landscape. So... I was able to solve the problem like this:

// If iPad, put the simulator on landscape mode
if UIDevice.current.userInterfaceIdiom == .pad { 
    XCUIDevice.shared.orientation = .landscapeLeft
}

// Perform the swipe
app.swipeDown(velocity: .fast)

// Restore device portrait mode
if UIDevice.current.userInterfaceIdiom == .pad { 
    XCUIDevice.shared.orientation = .portrait
}
Nicolas Yuste
  • 673
  • 9
  • 15
0

How do I have achieved this? This way below:

  1. Find a starting coordinates origin x and origin y of the poped up view, ref: How to tap on a specific point using Xcode UITests

  2. Then do the minus on coordinates to tap outside the frame of poped up view, Then do the tap action.

It will dismiss the Pop up , and tests will pass.

Neelam Verma
  • 3,232
  • 1
  • 22
  • 33