简体   繁体   中英

iOS UITesting How to Dismiss Popover (iPad Popover NOT Alert Style)

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)

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.

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
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM