Setting a picker view value when UI testing inconsistent with behaviour

Originator:d4rkf1br3
Number:rdar://25740585 Date Originated:15/04/2016
Status:Open Resolved:
Product:Developer tools Product Version:7.3
Classification:Bug Reproducible:Always
 
Summary:
The way that the UI testing code appears to be different to the way a user would use a UIPicker. 

A user typically scrolls the picker to the value they way. The UIPicker only triggers delegate methods when the user stops scrolling and ends the touch. 

UI testing's adjustToPickerWheelValue function on the other hand, behaves differently. It appears (after some testing) that adjustToPickerWheelValue calculates the number of picker values between the current value and the desired value, then issues the correct number of single value scrolls to move the picker to the desired result.

The problem with this is that this is effectively the same as the user selecting every single value between the current and desired one, trigger UIPicker delegate methods as it goes.

In addition, this causes faults in code when adjusts the picker when a value is selected. For example, in my code I have a picker value of "---" which I use to delimit sets of values in a picker. So my picker values might be as follows:

abc
def
---
ghi
jkl

I have a picker delegate method that looks like this:

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        var value = pickerValues[row]
        // Skip the delimiter.
        if value == "---" {
            pickerView.selectRow(++selectedRow, inComponent: 0, animated: true)
            return;
        }
        pickerValueDidChange()
    }

When the user scrolls to the "---" value, the picker automatically selects the next value -> "ghi". If they scroll to "ghi" directly, "---" is never actioned because the picker doesn't stop on that value.

But when UI testing does this, it ends up on the "jkl" value because  it selects each value on the way to "ghi", including the "---" value which then adds an extra scroll.

It appears that the UI testing picker code is not checking where it is at and therefore is unaware of the change made by the app code.

Steps to Reproduce:
1. Add a UIPicker with the values described above.
2. Add a picker didSelectRow with the code above.
3. Setup a UI test which tells the picker to goto value "ghi".
4. Assert the value is current.

Expected Results:
The assert passes with the picker showing "ghi" as the current value.

Actual Results:
The assert fails with the picker showing "jkl" as the current value.

Version:
7.3

Notes:


Configuration:


Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!