[英]Testing TapGesture with 6 repeats (iOS and Swift)
This might be a fun one. 这可能很有趣。 I'm setting up UI testing in XCode.
我正在XCode中设置UI测试。 One part of my app requires the user to tap on the screen 6 times to perform a particular action.
我的应用程序的一部分需要用户点击屏幕6次才能执行特定操作。 The code is below.
代码如下。
let tapGesture = UITapGestureRecognizer(target: self,action:#selector(self.doSomething(_:)))
tapGesture.numberOfTapsRequired = 6
aView.addGestureRecognizer(tapGesture)
Where I am having trouble is testing this gesture recognizer. 我遇到麻烦的地方是测试此手势识别器。 The following code is created by the test recorder, but doesn't work when just tested.
以下代码由测试记录器创建,但仅在测试时不起作用。
let app = XCUIApplication()
let elem = app.otherElements.containingType(.Image, identifier:"elementName").element
elem.tap()
elem.tap()
elem.tap()
elem.tap()
elem.tap()
elem.tap()
I even tried adding a slight delay between each element (about I've tried values between 1.0 and 0.02 seconds), but nothing seems to actually work. 我什至尝试在每个元素之间添加一个稍微的延迟(大约我尝试了1.0到0.02秒之间的值),但是似乎没有任何效果。
Any thoughts? 有什么想法吗?
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).
以最快的速度,在UI测试器中轻按一下会花费一秒钟多一点的时间,这太长了(甚至还不能完全关闭)。 So I had to make a workaround (aka: a hack)
因此,我不得不采取一种解决方法(又名:hack)
Here is my work-around. 这是我的解决方法。
In my view controller I did something like this: 在我的视图控制器中,我做了这样的事情:
#if !TEST #if!TEST
myButton.hidden = true myButton.hidden = true
#endif #万一
Modified my UI test code to find that button and do a simple tap instead. 修改了我的UI测试代码以找到该按钮,然后进行简单的点击。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.