Simulate a shake gesture with Swift 2.0 UI testing

I recently downloaded the beta version of Xcode 7 bundled with Swift 2.0. I use it to test my application. I built most of my tests using the xcode writer UI function.

My application responds to shake gestures, and I would like to programmatically initiate a shake gesture in my quick UI tests. Running a shake gesture while recording does not give any added code.

Is there any way to do this? Thanks in advance!

+5
source share
1 answer

The converted code from the message that was associated with is as follows:

func setShakeState(fp8: Int) { _shakeState = fp8 } func _setSubtype(fp8: Int) { _subtype = fp8 } 

and

 var m: UIMotionEventProxy = NSClassFromString("UIMotionEvent")._init() m.setShakeState(1) m._setSubtype(UIEventSubtypeMotionShake) UIApplication.sharedApplication().sendEvent(m) UIApplication.sharedApplication().keyWindow().motionBegan(UIEventSubtypeMotionShake, withEvent: m) UIApplication.sharedApplication().keyWindow().motionEnded(UIEventSubtypeMotionShake, withEvent: m) 

Here is the site I used to convert: https://objectivec2swift.com/#/converter .

0
source

All Articles