Post

Replies

Boosts

Views

Activity

Reply to Xcode12 iOS 14 Date Picker UI Testing adjust toPickerWheelValue issue
There still doesn't seem to be a supported method of changing the new date picker wheels as of Xcode 12.1. I've come up with this method to get around the issue: func adjustDatePicker(wheel: XCUIElement, to newValue: String) -> Bool {		 		let x = wheel.frame.width / 2.0 		let y = wheel.frame.height / 2.0 		// each wheel notch is about 30px high, so tapping y - 30 rotates up. y + 30 rotates down. 		var offset: CGFloat = -30.0 		var reversed = false 		let previousValue = wheel.value as? String 		while wheel.value as? String != newValue { 				wheel.coordinate(withNormalizedOffset: .zero).withOffset(CGVector(dx: x, dy: y + offset)).tap() 				let briefWait = expectation(description: "Wait for wheel to rotate") 				briefWait.isInverted = true 				wait(for: [briefWait], timeout: 0.25) 				if previousValue == wheel.value as? String { 						if reversed { 								// we already tried reversing, can't find the desired value 								break 						} 						// we didn't move the wheel. try reversing direction 						offset = 30.0 						reversed = true 				} 		} 		 		return wheel.value as? String == newValue }
Oct ’20