这可能很有趣。我正在XCode中设置UI测试。 我的应用程序的一部分要求用户点击屏幕6次以执行特定操作。代码如下。
let tapGesture = UITapGestureRecognizer(target: self,action:#selector(self.doSomething(_:)))
tapGesture.numberOfTapsRequired = 6
aView.addGestureRecognizer(tapGesture)
我遇到问题的地方是测试这个手势识别器。以下代码由测试记录器创建,但在刚测试时不起作用。
let app = XCUIApplication()
let elem = app.otherElements.containingType(.Image, identifier:"elementName").element
elem.tap()
elem.tap()
elem.tap()
elem.tap()
elem.tap()
elem.tap()
我甚至尝试在每个元素之间添加一点延迟(关于我尝试过1.0到0.02秒之间的值),但似乎没有任何实际工作。
有什么想法吗?
答案 0 :(得分:0)
Here is what I've found so far. At its fastest, a tap takes a little over one second in the UI tester, which is WAY too long (not even close by a wide margin). So I had to make a workaround (aka: a hack)
Here is my work-around.
In my view controller I did something like this:
#if !TEST
myButton.hidden = true
#endif
Modified my UI test code to find that button and do a simple tap instead.