简体   繁体   English

iOS UITesting 如何关闭 Popover(iPad Popover NOT Alert Style)

[英]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命中坐标在window
  • app.otherElements["PopoverDismissRegion"] Hitting elements behind the app.otherElements["PopoverDismissRegion"] 命中后面的元素
  • popover (which are not hittable at all)弹出窗口(根本不可点击)

When I record the it in XCode I get: app.otherElements["PopoverDismissRegion"]当我在 XCode 中记录它时,我得到: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)信息iOS 10.2,Xcode 8.2.1, iPad Air 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.点击窗口并关闭当前活动的弹出窗口。

Everything was working for me on iPhone simulators by just doing:一切都在 iPhone 模拟器上为我工作,只需执行以下操作:

app.swipeDown(velocity: .fast)

I started to have problems when I wanted the same test to run on iPad simulators.当我想要在 iPad 模拟器上运行相同的测试时,我开始遇到问题。 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.对其进行更多测试,我发现如果 iPad Simulator 处于横向模式,视图实际上会被关闭发送swipeDown手势。 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找到弹出视图的起始坐标原点 x 和原点 y,参考: 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.它将关闭弹出窗口,测试将通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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