简体   繁体   中英

How to change value of a custom adjustable control in XCTest UI Test?

My iOS app has a 5-star rating view. How can I change the number of selected stars in my XCTest UI test.

在此处输入图片说明

This view implements UIAccessibilityTraitAdjustable accessibility trait which allows users to change the number of stars by swiping up and down when "VoiceOver" setting is turned on in Settings > General > Accessibility.

I was wondering if I can use this accessibility feature in my UI tests to select the stars. Is there a way for a UI Test to send "accessibility increment/decrement" signals to the view? Is there any other way for me to change the number of selected stars in a UI test?

I tried using swipeRight and swipeLeft methods and they do interact with the view by changing the selected stars. The problem with that approach it is nondeterministic. When calling those swipe methods I do not know exactly how many stars will be selected and therefore I can not guarantee that my test will pass when it is run on devices with different screen sizes.

Is there a way for me to select the stars in this star rating control in an XCTest UI test?

Have you tried using adjustToNormalisedSliderPosition ?

If this doesn't work with the adjustable trait, you could try subclassing UISlider in your app, as recommended here . Writing a testable app is a big part of having solid quality processes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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