google / EarlGrey

:tea: iOS UI Automation Test Framework
http://google.github.io/EarlGrey/
Apache License 2.0
5.61k stars 741 forks source link

GREYPickerAction doesn't always work since Pickers don't always have a dataSource #1343

Open NachtRaveVL opened 4 years ago

NachtRaveVL commented 4 years ago

As the title says, I seem to have found several instances of UIPickerView controls which do not have a dataSource (such as the case with React Native components), thus the code in GREYPickerAction.m returns a nil'ed-out dataSource which then reports 0 rows and fails to function correctly.

Instead, a better solution would be akin to:

  NSInteger componentCount;
  if (pickerView.dataSource) {
    componentCount = [pickerView.dataSource numberOfComponentsInPickerView:pickerView];
  } else {
    componentCount = [pickerView numberOfComponents];
  }

and

  NSInteger columnRowCount;
  if (pickerView.dataSource) {
    columnRowCount = [pickerView.dataSource pickerView:pickerView numberOfRowsInComponent:_column];
  } else {
    columnRowCount = [pickerView numberOfRowsInComponent:_column];
  }
tirodkar commented 4 years ago

Thanks a ton for this. I'll send out a fix for this soon once I've tested it.

LeoNatan commented 4 years ago

This is actually a bug in RN, not in Earl Grey. The problem is they are relying on undocumented behavior, where if no data source is set, the picker itself becomes the data source. This behavior can break at any point.

I reported this here: https://github.com/react-native-community/react-native-picker/issues/74

And it was fixed here: https://github.com/react-native-community/react-native-picker/pull/96

@NachtRaveVL You should use the latest package containing this fix.